0

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?

2 Answers 2

0

You trying to return empty path to browser and you get 404. It's normal. Try to return String with path to controller that returns empty page:

@PostMapping(value = "/path") public String serve(final Model model) { if (everything_fine) { return "path_to_page_which_will_be_handled_by_view_controller"; } return "path_to_EMPTY_page_which_will_be_handled_by_view_controller"; } 
Sign up to request clarification or add additional context in comments.

Comments

0

Eventually split this in two requests, one to get the data on which deciding if the modal will be shown or not, and finally request the modal contents if needed.

Comments