1、js ajax 设置自定义header
1.1 方法一:
$.ajax({
type: "POST",
url: "Handler1.ashx",
contentType: "application/x-www-form-urlencoded",
beforeSend: function (request) {
request.setRequestHeader("token1", "Chenxizhang");
},
success: function (data) {
//your code
}
});
1.2 方法二:
$.ajax({
headers: {
"testheader": "test"
},
type: "POST",
url: "Handler1.ashx",
contentType: "application/x-www-form-urlencoded",
success: function (data) {
//your code
}
});
本文介绍了使用 jQuery 的 AJAX 方法设置自定义HTTP头部信息的两种方式。第一种方式是在 beforeSend 回调函数中通过 setRequestHeader 方法来实现;第二种方式则是直接在 AJAX 请求配置对象中指定 headers 属性。
1043

被折叠的 条评论
为什么被折叠?



