【发布时间】:2015-10-27 12:14:43
【问题描述】:
我向服务器发送 ajax 发布请求并以 302 重定向响应。除 IE 外,所有浏览器都遵循此重定向。我在 IE 开发工具的网络选项卡中看到收到 302 响应。
同样 jQuery .fail(function(jqXHR, textStatus) {...}) 回调在jqXHR 中返回以下数据:
[object Object]{readyState: 0, status: 0, statusText: "error"}
这很奇怪,因为状态不是 302。
在 IE 11 上测试。
编辑 响应头:
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 标头,但不能在 IE 中执行此操作。见:http://www.yiiframework.com/doc-2.0/yii-web-response.html#redirect()-detail。
【问题讨论】:
-
你是说fail回调是在IE中执行的?
-
@Michael 在所有浏览器中执行失败回调。我认为重定向响应没问题。
-
您可以在后端代码的标头中发布您返回的重定向行吗?
-
@Michael,添加到我的问题中。
-
谢谢。您使用 ajax 请求的 url 是什么?
标签: javascript jquery ajax internet-explorer yii2