重定向从Ajax调用主窗口重定向、窗口、Ajax

2023-09-10 21:26:05 作者:冷眼旁观世俗分骚

我有一个AJAX调用一个控制器,检查认证,在没有验证存在,它发送呼叫开始到到登录控制器谁检查,如果它是一个XHR请求。如果它呈现包含page.redirect_to到到登录路径中的RJS和主窗口将被重定向到登录页面。这完美的作品在谷歌浏览器,但无法在Firefox。

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.

只有code在RJS文件是:

the only code in the rjs file is:

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

正如我所说的,它完美的作品在Chrome但Firefox(3.6版)拒绝重定向的主窗口。没有人有任何想法,我怎么能得到这个工作在Firefox呢?

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?

推荐答案

您可能需要处理来自Ajax请求的响应,并通过JavaScript重定向:

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

window.location = urlToDirectTo;

我想大多数的浏览器会重定向Ajax请求本身,而不是从Ajax请求被做了页面。 Here's答案来,详细的解决了类似的问题。

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.