javascript - XMLHttpRequest 响应在 Internet Explorer 中没有 header

标签 javascript extjs xmlhttprequest

我正在使用 ExtJS 向不返回响应文本的服务发出 XMLHttpRequest,仅返回 204 和响应 header TotalNearby。该调用在 Firefox 中运行完美,但在 Internet Explorer 8 中,两个警告框都是空的。我做错了什么?

Ext.Ajax.request({
    url: 'services/getNearby',
    method: 'GET',
    params: {
        'lat': 34,
        'lon': -90
    },
    headers: {
        'Authorization': AUTH_TOKEN
    },
    success: function(response) {
        if (response.status == 204) {
            alert(response.getAllResponseHeaders());
            alert(response.getResponseHeader('Total-Nearby'));
        }
    },
    failure: function(response) {
        alert('Server status ' + response.status);
    }
});

最佳答案

根据网站http://www.enhanceie.com/ie/bugs.asp这是一个 IE 7/8 错误:

IE0013: IE XMLHTTP implementation turns 204 response code into bogus 1223 status code

Described here http://dev.jquery.com/ticket/1450, the XMLHTTPRequest object in IE will return a status code of 1223 and drop all response headers if the server returns a HTTP/204 No Content response.

This is caused by an internal design artifact of URLMon (binding returns Operation Aborted (1223) if the server returns no content in response to a request).

Repros in IE8, IE7 (and probably earlier).

Workaround: Treat "1223" as equivalent to a 204. Note: HTTP headers remain unavailable in this case.

如果您看到空警报,这意味着 IE 没有将状态代码更改为 1223,那么该部分错误可能已经修复。但是,我会更担心声明:

Note: HTTP headers remain unavailable in this case.

因为这似乎是您面临的问题。您是否需要使用不响应内容的服务?您可能更适合返回带有消息正文的典型响应。

关于javascript - XMLHttpRequest 响应在 Internet Explorer 中没有 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4268931/

相关文章:

javascript - 如何使用 JavaScript 在浏览器中检测 WebRTC 支持的视频和音频编解码器?

javascript - 状态更改时,React jsx 数组组件不会重新渲染

javascript - 就 CORS 而言,通过 XMLHttpRequest、curl 和浏览器 URL 获取请求之间有什么区别?

javascript - XMLHttpRequest() 不发送 FormData() 导致 PHP $_FILES 数组为空并且没有上传文件

ajax - Internet Explorer - 由于错误 c00ce514,无法完成操作

javascript 克隆元素树并更改克隆中的所有 ID

javascript - React Native fetch 仅在第二次或第三次尝试时返回

extjs - 在 Extjs 中自动隐藏视口(viewport)的区域

javascript - extjs 示例代码不起作用

maven - 我可以使用 Maven 和 Sencha Cmd 而不是 Ant,还是必须使用 Ant?