I am trying to POST a form data to my server. I have wrote the following ajax call but I keep getting 400 Bad error. Any help?
$(document).ready(function(){
// click on button submit
$("#submit").on('click', function(){
// send ajax
$.ajax({
url: "/compare",
type : "POST",
contentType : 'application/json; charset=utf-8',
data : $('#form').serialize(),
success : function(result) {
console.log(result);
},
error: function(xhr, resp, text) {
console.log(xhr, resp, text);
}
})
});
});
The following is my HTML form:
<form id="form">
<p>Input the URL of 2 images!</p>
<input id="img1" name="img1" type="text" placeholder="Image 1 URL">
<input id="img2" name="img2" type="text" placeholder="Image 2 URL">
<input id="submit" type="submit" value="Compare!">
</form>