开发者

Redirecting main window from ajax call

开发者 https://www.devze.com 2023-03-28 14:41 出处:网络
I have a ajax call to a controller that checks for authentication, when no authentication exists it sends the call onwards to the signin controller who checks if it is a xhr request. If it is it rende

I have a ajax call to a controller that checks for authentication, when no authentication exists it sends the call onwards to the signin controller who checks if it is a xhr request. If it is it renders an rjs containing a page.redirect_to to the s开发者_StackOverflowignin path and the main window is redirected to the signin page. This works flawlessly in google chrome but fails in Firefox.

the only code in the rjs file is:

page.redirect_to("http://localhost:3000/signin")

As i said, it works flawlessly in chrome but Firefox(v3.6) refuses to redirect the main Window. Does anyone have any ideas as to how i can get this to work in Firefox as well?


Are there any errors appearing in the console?

Would it not be easier to respond to "js" and render a js template with something like:

window.location = "http://localhost:3000/signin"

On a bit of a tangent, should you really be redirecting to "localhost:3000" absolutely anyway? Maybe there is a different solution?


You will probably need to handle the response from the ajax request and redirect via JavaScript:

window.location = urlToDirectTo;

I think most browsers will redirect the ajax request itself, not the page from which the ajax request was made. Here's an answer to a similar question that details the solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消