重定向从Ajax调用主窗口 [英] Redirecting main window from ajax call

查看:140
本文介绍了重定向从Ajax调用主窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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请求被做了页面。 <一href="http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call/1534662#1534662">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.

这篇关于重定向从Ajax调用主窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆