I'm trying to send an object in JSon format to my Java Webservice by AJAX, but I was not successful, I already tested wrong formats, which are not JSon's, as "string", and the database reports error properly, and therefore should report that the object was saved, so the html does not return the 'alert' either. Here is my code below:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scriptsrc="scripts/jquery.min.js.download"></script>
<script src="scripts/jquery.imagemapster.js.download"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
var myJSon = {"Aluno":"nome", "Respostas":[], "Sessao":[] };
type: "POST",
url: 'http://localhost:8080/Servidor/server',
dataType: "json",
data: JSON.stringify(myJSon),
sucess: function (data){
alert('Sucess');
},
error: function () {
alert('Error');
}
});
});
});
</script>
</head>
<body>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>