This is my first post. I’m sorry for my english…
I have problem with postJSON and returning partial view with ModelAndView.
My controller:
@RequestMapping(method=RequestMethod.POST, value = "/addUrl.html")
public @ResponseBody ModelAndView addSubMenu(@RequestBody Menu menu) {
ModelAndView mav = new ModelAndView(PathConfig.MENU_DIR + "show_url");
int id = menuService.saveOrUpdateMenu(1, menu.getTitle(), menu.getUrl(), 4, "pl");
mav.addObject("submenu", menuService.get(id));
return mav;
}
My ajax code:
$("#menuUrl").submit(function(){
var menu = $(this).serializeObject();
$.ajax({
type: "POST",
url: config.resourcePath+"/addUrl.html",
data: JSON.stringify(menu),
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(response){
$( "#site" ).append(response);
},
error: function(e){
alert("Server did not response.");
}
});
});
But… I have error: Server did not response…
How I can render partial view with json?
Thanks.
And controller returning ModelAndView.
It’s working.