当前位置:  开发笔记 > 编程语言 > 正文

在IE中,jquery的"X-Requested-With"标题变为"x-requested-with"(小写)

如何解决《在IE中,jquery的"X-Requested-With"标题变为"x-requested-with"(小写)》经验,为你挑选了2个好方法。

为什么要转换为小写?在Firefox中它是:"X-Requested-With".在IE中,它表示为:"x-requested-with"



1> Kieran Hall..:

根据RFC 2616,HTTP方法应该区分大小写,但HTTP标头应该不区分大小写.


因此,"为什么IE这样做"的答案是"因为它可以";-)

2> Kevin Hakans..:

我注意到了类似的东西.看一下示例代码以及添加一些自定义HTTP标头时的功能.首先是JavaScript代码,然后是来自IE8,Safari4和Firefox3的Fiddler转储(仅限自定义标头).请注意,Firefox尊重大小写,IE转换为小写,Safari转换为大写.

但是,如前所述,服务器将这些视为不区分大小写,因此无关紧要.

function doXHR() {
  var request = new XMLHttpRequest();
  request.open('GET', '/header/header.txt');
  request.setRequestHeader('x-lowercase', 'X-lowercase');
  request.setRequestHeader('x-Propercase', 'X-Propercase');
  request.setRequestHeader('x-CamelCase', 'X-CamelCase');
  request.setRequestHeader('x-UPPERCASE', 'X-UPPERCASE');
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      console.log('Received XMLHttpRequest callback: \n' + request.responseText);
    }
  };
  request.send("");
}

User-Agent:Mozilla/4.0(兼容; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618 )

x-lowercase: X-lowercase
x-camelcase: X-CamelCase
x-uppercase: X-UPPERCASE
x-propercase: X-Propercase

用户代理:Mozilla/5.0(Windows; U; Windows NT 6.0; en-US)AppleWebKit/528.18(KHTML,类似Gecko)版本/ 4.0 Safari/528.17

X-Lowercase: X-lowercase
X-Uppercase: X-UPPERCASE
X-Camelcase: X-CamelCase
X-Propercase: X-Propercase

User-Agent:Mozilla/5.0(Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6)Gecko/2009011913 Firefox/3.0.6(.NET CLR 3.5.30729)

x-lowercase: X-lowercase
x-Propercase: X-Propercase
x-CamelCase: X-CamelCase
x-UPPERCASE: X-UPPERCASE

推荐阅读
谢谢巷议
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有