KutaBeach
KutaBeach

Reputation: 1495

Spring MVC redirect: new page is opened in div

Here is a problem I have encountered.

I have jsp page which has a javascript openForm function. This function fetches data from server URL that relates to dialog.jsp and inserts that code into the body of my page. I.e. it looks like

function showDialog(url){
    $.get(url,function(data){
        $("body").append(data);
    })
}

OK, but after user deals with that dialog I want to redirect him to some better place. I use return createRedirectModelAndView(URL_CONSTANT) in the controller, responsible for handling POST from that dialog.

It works, but here is a problem: a new page (redirect target) is opened INSIDE that dialog div. So the parent page (on which user clicks showDialog) still exists and it looks like the redirect is redirecting user inside dialog. This effect can be cool in some situations, but not in mine. I want total redirect - close that page and open another.

Where I went wrong?

Upvotes: 1

Views: 1442

Answers (1)

Dave Newton
Dave Newton

Reputation: 160321

If you want to redirect from an Ajax call then you should return the redirect URL from the server and do the redirect/location change from JavaScript.

Upvotes: 3

Related Questions