从ajax调用重定向主窗口
我对检查身份验证的控制器进行了 ajax 调用,当不存在身份验证时,它将调用向前发送到登录控制器,该登录控制器检查它是否是 xhr 请求。如果是,它会将包含 page.redirect_to 的 rjs 渲染到登录路径,并且主窗口将重定向到登录页面。这在 google chrome 中完美运行,但在 Firefox 中失败。
rjs 文件中的唯一代码是:
page.redirect_to("http://localhost:3000/signin")
正如我所说,它在 Chrome 中完美运行,但 Firefox(v3.6) 拒绝重定向主窗口。有谁知道我如何让它在 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
控制台中是否出现任何错误?
响应“js”并使用以下内容渲染 js 模板不是更容易吗:
稍微切线一下,您真的应该绝对重定向到“localhost:3000”吗?也许有不同的解决方案?
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:
On a bit of a tangent, should you really be redirecting to "localhost:3000" absolutely anyway? Maybe there is a different solution?
您可能需要处理 ajax 请求的响应并通过 JavaScript 重定向:
我认为大多数浏览器会重定向 ajax 请求本身,而不是发出 ajax 请求的页面。 这是一个答案 到一个类似的问题,详细说明了解决方案。
You will probably need to handle the response from the ajax request and redirect via JavaScript:
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.