Redirecting main window from ajax call

拈花ヽ惹草 提交于 2019-12-11 07:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!