我向服务器发送 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()-detail和 https://github.com/yiisoft/yii2/issues/9670
关于javascript - Internet Explorer 不会重定向 ajax 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367746/