如何通过Ajax设置请求标头

时间:2015-08-12 11:35:09

标签: ajax header request

我尝试通过两种方式设置请求标头:
1:

$.ajax({
type: "GET",
url: "https://d.la1-c1-lon.salesforceliveagent.com/chat/rest/System/SessionId",
headers: {
    "X-LIVEAGENT-API-VERSION" : 34,
    "X-LIVEAGENT-AFFINITY" : null
},
response:'json'
});

2:

$.ajax({
type: "GET",
beforeSend: function (xhr) {
        xhr.setRequestHeader('X-LIVEAGENT-API-VERSION', 34);
        xhr.setRequestHeader('X-LIVEAGENT-AFFINITY', null);
    },
url: "https://d.la1-c1-lon.salesforceliveagent.com/chat/rest/System/SessionId",   
response:'json'
});

在浏览器控制台中,我等待“X-LIVEAGENT-AFFINITY:null”和“X-LIVEAGENT-API-VERSION:34”。
但我真的看到“Access-Control-Request-Headers:accept,x-liveagent-affinity,x-liveagent-api-version”

0 个答案:

没有答案