我想添加一个自定义头的AJAX POST请求从jQuery。
我试过了:
$.ajax({
type: 'POST',
url: url,
headers: {
"My-First-Header":"first value",
"My-Second-Header":"second value"
}
//OR
//beforeSend: function(xhr) {
// xhr.setRequestHeader("My-First-Header", "first value");
// xhr.setRequestHeader("My-Second-Header", "second value");
//}
}).done(function(data) {
alert(data);
});
当我发送这个请求,我看FireBug,我看到这个头:
OPTIONS xxxx/yyyy HTTP/1.1
. xml 主持人:127.0.0.1:6666 < br / > User-Agent: Mozilla/5.0 (Windows NT 6.1;WOW64;rv:11.0) Gecko/20100101 Firefox/11.0
接受:text / html, application / xhtml + xml应用程序/ xml; q = 0.9, /; q = 0.8 < br / > 接收语言:fr - fr; q = 0.8, en - us; q = 0.5, en; q = 0.3 < br / > Accept-Encoding: gzip, deflate
连接:维生< br / > 产地:空< br / > Access-Control-Request-Method:文章< br / > Access-Control-Request-Headers: my-first-header my-second-header < br / > 编译指示:no - cache < br / > cache - control: no - cache < br / > < / p >
为什么我的自定义头文件去Access-Control-Request-Headers
:
Access-Control-Request-Headers: my-first-header my-second-header
我期待的头值是这样的:
My-First-Header:第一个值
My-Second-Header: second value
这可能吗?