I'm making an ajax request and I have two situations, where if everything is ok I return a page which will be rendered in a modal else return empty string and don't show any modal at all.
Here is a sample of how should my controller look like:
@PostMapping(value = "/path")
public String serve(final Model model)
{
if (everything_fine)
{
return "path_to_page_which_will_be_handled_by_view_controller";
}
return StringUtils.EMPTY;
}
and the ajax request is something like this:
$.ajax({
type: 'POST',
url: '/path',
error: function (data) {
//handle error
},
success: function (data) {
if (data) {
// render response in modal
} else {
// show some other stuff
}
}
});
For the situation where jsp is returned request works fine, when empty string is returned I get 404 and ajax request goes on the error branch when finished. I guess this is because view controller doesn't find any view for the empty string returned, do you have any idea how can I accomplish my scenario?