jQuery JSONP ajax,未设置身份验证标头
问题描述:
我正在尝试使用以下设置向Google通讯录API发出ajax请求:
I'm trying to make an ajax request to the google contacts API with the following setup:
$.ajax({
url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all",
dataType: 'jsonp',
data: {
alt: 'json-in-script'
},
headers: {
'Authorization': 'Bearer ' + token
},
success: function(data, status) {
return console.log("The returned data", data);
}
});
但是认证标头似乎没有设置。有什么想法?
But the Authentication header doesn't seem to get set. Any ideas?
答
我最近遇到了同样的问题。试试这个:
I had the same problem recently. Try this:
$.ajax({
url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all",
dataType: 'jsonp',
data: {
alt: 'json-in-script'
},
success: function(data, status) {
return console.log("The returned data", data);
},
beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + token); }
});
编辑:看起来无法用JSONP完成。 修改JSONP请求的HTTP标头
Looks like it can't be done with JSONP. Modify HTTP Headers for a JSONP request