<!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><formaction="/" 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 can not load link . In '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 does not enter the alert at all.
Documentation: link
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>