1
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.post demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<form action="/" id="searchForm">
<input type="text" name="s" placeholder="Search...">
<input type="submit" value="Search">
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<script>
$( "#searchForm" ).submit(function( event ) {
// Stop form from submitting normally
event.preventDefault();
// Get some values from elements on the page:
var $form = $( this ),
term = $form.find( "input[name='s']" ).val(),
url = $form.attr( "http://192.168.1.140:8080/vectis/account/vialaser/webservice/cliente/consultarCliente" );
// Send the data using post
var posting = $.post( "http://192.168.1.140:8080/vectis/account/vialaser/webservice/cliente/consultarCliente", { cpfCliente: term } );
// Put the results in a div
posting.done(function( data ) {
alert('Passou');
});
});
</script>
</body>
</html>
I have this code, but look what it returns:
Xmlhttprequest cannot load http://192.168. 1.140:8080/vectis/Account/vialaser/webservice/client/consultarCliente. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'null' is therefore not allowed access. The Response had HTTP status code 422.
He’s not on the alert at all.
Documentation: http://api.jquery.com/jQuery.post/
With ajax:
<script>
jQuery(document).ready(function() {
jQuery('#conversion-form').submit(function(){
event.preventDefault();
$.ajax({
type: 'POST',
url: "http://localhost:8080/vectis/account/vialaser/webservice/cliente/consultarCliente",
data: 'cpfCliente=078.736.879-29',
contentType: "application/x-www-form-urlencoded",
crossDomain : true,
dataType: 'application/json',
success: function(data) { alert("Success"); },
error: function(data) { alert('Failed!'); },
});
return false;
});
});
</script>
<form class="form-horizontal" id="conversion-form">
<div class="form-group" style="margin-top: 15px;">
<label class="col-md-4 control-label" for="email">E-mail</label>
<div class="col-md-4">
<input id="cpfCliente" name="cpfCliente" type="text" class="form-control input-md" required="true">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="botaoenviar"></label>
<div class="col-md-4">
<button id="botaoenviar" name="botaoenviar" class="btn btn-success">Enviar</button>
</div>
</div>
</form>
Possible duplicate of CORS - No 'Access-Control-Allow-Origin' header is present on the requested Resource
– BrTkCa
Didn’t help.....
– Alisson Hoepers
What seems like this error is that the link you are trying to make the request has controlled access, and you are not allowed to access...
– LocalHost
But I put a breakpoint on my app and it comes...
– Alisson Hoepers
Look if this link can help you... esta ingles http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource
– LocalHost
but I think it’s still the same as when Lucas was there...
– LocalHost
This plugin will probably save you: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
– MarioAleo
Poís is, but my customers will not be able to install the plugin, right?
– Alisson Hoepers
CORS always needs to be authorized by the server, not the client. If the service you are consuming does not allow, by normal means you will not be able to do anything. There is how to add the plugin in chome or use a proxy, but it is neither assertive nor practical.
– BrTkCa
I edited the implementation question with ajax, the same happens.
– Alisson Hoepers
So I suggested as duplicate, it is a very common problem and it already has many discussions.
– BrTkCa
@Alisson, $.post and $.ajax are basically the same thing - both are ajax requests.
– BrTkCa
@Alisson, when debugging on the localhost Cors is barred regardless of how the back is configured, when it is in production Cors will only be blocked if the back does not give permission, so no, your clients will not have to install, only Voce to debug on the localhost
– MarioAleo
Now does not return any of Xmlhttprequest cannot load, but still enters the error alert
– Alisson Hoepers