Well, sometime ago I did a feature on my website which consists of performing a filter (called AJAX ), and in my action I simply return a view I am rendering via callback , but if it is possible I would like the ModelAndView to be responsible for that.)
Call AJAX :
function perfectDestinationFilter(){
$.ajax({
type: "GET",
url: "/viatge/perfect-travel-filter",
data: $('#form-filter-perfect-travel').serialize(),
success: function (response) {
$('html').html( response );
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
Action responsible return my page with the destinations found:
@RequestMapping(value = "/perfect-travel-filter", method = RequestMethod.GET)
public ModelAndView getDestinations(@RequestParam String social, @RequestParam String economic, @RequestParam String trip, @RequestParam String weather, @RequestParam String general, Model model) throws SQLException{
if(Strings.isNullOrEmpty(social) || Strings.isNullOrEmpty(economic) || Strings.isNullOrEmpty(trip) || Strings.isNullOrEmpty(weather) || Strings.isNullOrEmpty(general)){
return new ModelAndView("site/destinations02", "perfectDestinationError", true);
}else{
return new ModelAndView("site/destinations02", "perfectDestinations", destinationFacade.filterDestinations(economic, general, social, weather, trip));
}
}
Well, this approach even works through callback ( $('html').html( response );
), but the problem is that the page renders with broken layout jQuery does not work perfectly.
Is there any other possibility? Would I have avoided the callback leaving the responsibility for the TilesViewResolver to accomplish this?