I am posting to my database (for context using GAE, and Objectify as a DAO) and it posts correctly (and the backend returns a response of 202), however, under the Ajax it is not calling the "success" block (i.e. in the method below even when it post's correctly, it calls alert("error1")). The source code for Ajax says a Post is supposed to call the success block when the status is between 200 and 300. Any ideas why it isn't working? Any help would be great!
function userExist() {
var rootUrl = "http://localhost:8888/api/";
function loginToJSON() {
return JSON.stringify({
"username": $('#username').val(),
"password": $('#password').val()
});
}
//System.out.println(loginToJSON());
$.ajax({
type: 'POST',
contentType: 'application/json',
url: rootUrl + 'userLogin',
dataType: "json",
data: loginToJSON(),
success: function(data, status, jqXHR) {
alert("success");
},
error: function(jqXHR, status, errorThrown){
alert("error1");
}
});
}
The relevant java backend is
@POST
public Response login(Login l) {
if (loginService.checkCred(l)) {
return Response.status(202).build();
} else {
return Response.status(403).build();
}
}