问题
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 signin 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?
回答1:
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?
回答2:
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.
来源:https://stackoverflow.com/questions/7075999/redirecting-main-window-from-ajax-call