I am working on a project adding some Ajax to a Spring-MVC project. I removed the tags
<form:errors path="fieldName"/>
That would insert the error the JSP, now I am trying to make some Ajax code to display the errors on the page. can anyone should me how to updated the following code to display the error messages and NOT the errors?
success: function(response)
{
// we have the response
$('#error').hide('fast');
if(response.status == "SUCCESS")
{
$('#error').hide('fast');
alert("Thanks for submitting. We will get back to you as soon as possible.\n\n" + response.result);
$('#error').hide('slow');
}else
{
errorInfo = "";
for( i = 0 ; i < response.result.length ; i++){
errorInfo += "<br>" + (i + 1) +". " + response.result[i].code;
}
$('#error').html("Please correct following errors: " + errorInfo);
$('#info').hide('slow');
$('#error').show('slow');
$('#input').show('slow');
}
},
error: function(e){
alert('Error: ' + e);
}
});
The above code works to display the errors but not the error messages
below is my java code:
@RequestMapping(value = "/ajax.html", method = RequestMethod.POST)
public @ResponseBody
JsonResponse addMessage(@Valid
@ModelAttribute(value = "memberrequest") MemberRequest memberrequest,
BindingResult result) {
JsonResponse res = new JsonResponse();
if (!result.hasErrors()) {
res.setStatus("SUCCESS");
// Setting data over to RT
String Ticket = zzz.sentWebRequest(memberrequest);
/*
* Setting out the ticket number to be displayed to user
*/
Map<String, Object> model = new HashMap<String, Object>();
Ticket t = new Ticket();
t.setTicketDetails(Ticket);
model.put("ticket", t);
res.setResult(Ticket);
} else {
res.setStatus("FAIL");
res.setResult(result.getAllErrors());
}
return res;
}
}
JSON Class:
public class JsonResponse { private String status = null; private Object result = null;
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public Object getResult() { return result; }
public void setResult(Object result) { this.result = result; }
}