jQuery: getResponseHeader not working in IE when used inside error function

牧云@^-^@ 提交于 2019-12-23 19:32:02

问题


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') );
    }
}
);

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.

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

Any idea on how to circumvent this behavior in IE?


回答1:


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.



来源:https://stackoverflow.com/questions/10649156/jquery-getresponseheader-not-working-in-ie-when-used-inside-error-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!