【问题标题】:jQuery: getResponseHeader not working in IE when used inside error functionjQuery:在错误函数中使用时,getResponseHeader 在 IE 中不起作用
【发布时间】:2012-05-25 19:45:03
【问题描述】:

我正在使用 jQuery 1.7.1。连同Ajax Form plugin,最新版本可用。当我执行 Ajax 请求时,例如:

$('form').ajaxForm (
{
    success: function ( data )
    {
        alert ( data.responseText );
    },
    error: function ( data, status, error )
    {
        alert ( data.getResponseHeader('Content-type') );
    }
}
);

如果请求返回错误,IE(在我的例子中是 IE9)将始终为 Content-type 标头或任何其他标头返回 undefined。 data.responseText 属性也返回 null。 Gecko 或 Webkit 浏览器并非如此。

这些是 Ajax 请求返回的响应标头的示例:

Response         HTTP/1.1 400 Bad Request
Date             Fri, 18 May 2012 08:15:32 GMT
Server           Apache/2.2.14 (Ubuntu)
X-Powered-By     PHP/5.3.2-1ubuntu4.15
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
Connection       close
Content-Type     text/html

知道如何在 IE 中规避这种行为吗?

【问题讨论】:

    标签: jquery internet-explorer header ajaxform


    【解决方案1】:

    我遇到了类似的问题。由于某种原因,IE 不会检索头部,除非您在使用 GET 时未更改的静态页面上明确要求它。将 ajax 类型更改为“HEAD”而不是 GET 或 POST,它应该会拉取响应标头。

    【讨论】:

    • 问题是我使用的是 RESTful 服务器,将请求方法更改为 HEAD 而不是 GET 或 POST 对我没有好处。 jQuery 1.9.0 仍然有同样的问题。我想很明显问题出在 IE 方面。顺便说一句,很抱歉没有早点回答。我的错。
    猜你喜欢
    • 2011-10-16
    • 2012-07-21
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多