javascript - Internet Explorer 不会重定向 ajax 响应

标签 javascript jquery ajax internet-explorer yii2

我向服务器发送 ajax post 请求并使用 302 重定向进行响应。除 IE 之外的所有浏览器都遵循此重定向。我在 IE 开发工具的“网络”选项卡中看到收到了 302 响应。

此外,jQuery .fail(function(jqXHR, textStatus) {...}) 回调会在 jqXHR 中返回以下数据: [object Object]{readyState: 0, status: 0, statusText: "error"}

这很奇怪,因为状态不是 302。

在 IE 11 上测试。

编辑 响应 header :

Response    HTTP/1.1 302 Found
Date    Tue, 27 Oct 2015 12:24:47 GMT
Server  Apache/2.4.10 (Debian) PHP/5.6.7-1
X-Powered-By    PHP/5.6.7-1
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control   no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma  no-cache
X-Redirect  http://mysiteaddress.com/somepage/
Set-Cookie  PHPSESSID=123; path=/; HttpOnly
Content-Length  0
Keep-Alive  timeout=15, max=96
Connection  Keep-Alive
Content-Type    text/html; charset=UTF-8

EDIT2 我猜这是 Yii2 框架特定的错误。客户端脚本必须处理 X-REDIRECT header ,但在 IE 中无法执行此操作。请参阅:http://www.yiiframework.com/doc-2.0/yii-web-response.html#redirect()-detail .

最佳答案

当您使用 yii\web\Response::redirect() 方法时,这是 Yii2 特定的错误/行为。 如果您返回代码 200 而不是正确的重定向代码 302,一切似乎都工作正常。

参见: http://www.yiiframework.com/doc-2.0/yii-web-response.html#redirect()-detailhttps://github.com/yiisoft/yii2/issues/9670

关于javascript - Internet Explorer 不会重定向 ajax 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367746/

相关文章:

javascript - 如何使用 Reactjs 中的按钮重定向到另一个页面

javascript - Owl Carousel 复制示例

javascript - JSONP 没有收到任何回调?

php - 对 php 文件进行 AJAX 调用 --> 然后退出浏览器 --> php 文件是否仍会完全运行?

jquery - 优化 jQueryMobile : problems with selectively including external JS files only when they are needed 代码

javascript - 显示和隐藏表格的链接

javascript - 异步推送数组中的项目

javascript - ui.draggable ("destroy"的 jquery ui 错误)

javascript - 在textarea中隐藏标签但要实现标签的效果

javascript - 通过 jsquery/ajax 注入(inject)的页面在任何 Chromium 浏览器中都无法正确显示