【问题标题】:Internet Explorer doesn't redirect on ajax responseInternet Explorer 不会重定向 ajax 响应
【发布时间】: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


【解决方案1】:

当您使用 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

【讨论】:

  • 2020 年仍在发生,但效果很好,因为 FF 不喜欢在发布数据的 ajax 后有 location.reload,所以 PRG 模式是最好的解决方案,提交服务器“ok”响应似乎满足IE为此。
猜你喜欢
  • 1970-01-01
  • 2013-06-24
  • 2015-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多