I have the following jQuery ajax code:
<script>
$(function() {
$("button").click(function() {
$.ajax({
url : "signin.html",
type : "post",
cache: false,
data : "userName=" +$("#userName").val()+ '&password='+$("#password").val(),
success : function(data) {
var obj = jQuery.parseJSON(data);
var msg = '<span>' + obj.message + '</span>';
$('#message').html(msg);
},
//EDIT
error: function(){
alert('Error in response...');
}
});
});
});
</script>
<div id="message"></div>
I have spring controller which sends message as responses which I am trying to print in the message box. I see the request processed by the controller but the message from the controller is not getting displayed in the page. What am I doing wrong here?
public @ResponseBody ModelAndView loginUser(request attributes here){
isUserExisits = service.authenticateUser(userBO);
if (isUserExisits) {
model.addObject("message", "Login Success");
} else {
model.addObject("message", "Login Failed");
}}
EDIT:- I have added error callback after 'success' and error call back function is getting called.