jQuery:getResponseHeader在内部错误函数中使用时不能在IE中工作 [英] jQuery: getResponseHeader not working in IE when used inside error function

查看:154
本文介绍了jQuery:getResponseHeader在内部错误函数中使用时不能在IE中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery 1.7.1。以及最新版本的 Ajax表格插件。当我做一个Ajax请求时,例如:

I am using jQuery 1.7.1. along with the Ajax Form plugin, latest version available. When I do an Ajax request, such as:

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

如果请求返回错误,IE(IE9,在我的情况下)将始终返回undefined内容类型标题或任何其他标题。 data.responseText属性也返回null。对于Gecko或Webkit浏览器,情况并非如此。

If the request returns an error, IE (IE9, in my case) will always return undefined for the Content-type header or any other header for that matter. The data.responseText property also returns null. This is not the case for Gecko or Webkit browsers.

以下是Ajax请求返回的响应标头示例:

These are an example of the response headers that the Ajax request is returning:

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中的这种行为的任何想法?

Any idea on how to circumvent this behavior in IE?

推荐答案

我有类似的问题。出于某种原因,除非您在使用GET时没有更改的静态页面上明确要求,否则IE将不会检索头部。将ajax类型更改为HEAD而不是GET或POST,并且它应该提取响应头文件。

I had a similar problem. For some reason IE won't retrieve the head unless you explicitly ask for it on static pages that haven't changed when you use GET. Change the ajax type to "HEAD" instead of GET or POST and it should pull the response headers.

这篇关于jQuery:getResponseHeader在内部错误函数中使用时不能在IE中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆