jqXHR.getAllResponseHeaders()将不会返回所有的头

编程入门 行业动态 更新时间:2024-10-28 16:27:45
本文介绍了jqXHR.getAllResponseHeaders()将不会返回所有的头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 jQuery.ajax()电话后 jqXHR.getAllResponseHeaders()将不会返回的所有头。服务器响应与以下标题:

连接:保持活动 内容长度:64 内容类型:应用程序/ JSON 的X我-CustomHeader:什么

getAllResponseHeaders()只返回了:

内容类型:应用程序/ JSON

我是什么做错了吗?

示例

VAR请求= {   URL:api.someExternalDomain/resource/,   类型:的someMethod   成功:功能(数据,textStatus,jqXHR){     的console.log(jqXHR.getAllResponseHeaders());   } }; $阿贾克斯(要求);

解决方案

从jQuery的官方网站:

  

在present,由于Firefox的一个错误的地方.getAllResponseHeaders()   返回虽然.getResponseHeader空字符串(内容类型)   返回一个非空字符串,自动解码JSON CORS响应   在Firefox中使用jQuery不支持。

api.jquery/jQuery.ajax/

After a jQuery.ajax() call jqXHR.getAllResponseHeaders() won't return all the headers. The server responded with the following headers:

Connection: keep-alive Content-Length: 64 Content-Type: application/json X-My-CustomHeader: whatever

getAllResponseHeaders() returned only:

Content-Type: application/json

What am I doing wrong?

Example

var request = { 'url': 'api.someExternalDomain/resource/', 'type': someMethod, 'success': function(data, textStatus, jqXHR) { console.log(jqXHR.getAllResponseHeaders()); } }; $.ajax(request);

解决方案

From jquery official website:

At present, due to a bug in Firefox where .getAllResponseHeaders() returns the empty string although .getResponseHeader('Content-Type') returns a non-empty string, automatically decoding JSON CORS responses in Firefox with jQuery is not supported.

api.jquery/jQuery.ajax/

更多推荐

jqXHR.getAllResponseHeaders()将不会返回所有的头

本文发布于:2023-11-05 16:11:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jqXHR   getAllResponseHeaders

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!