I want to send a json with Ajax to the Spring MVC controller but I can not get anything, I do not know what I'm failing
Javascript:
var search = {
"pName" : "bhanu",
"lName" :"prasad"
}
var enviar=JSON.stringify(search);
$.ajax({
type: "POST",
contentType : 'application/json; charset=utf-8',
url: 'http://localhost:8080/HelloSpringMVC/j',
data: enviar, // Note it is important
success :function(result) {
// do what ever you want with data
}
});
Spring MVC:
@RequestMapping(value ="/j", method = RequestMethod.POST)
public void posted(@RequestBody Search search) {
System.out.println("Post");
System.out.println(search.toString());
}