Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  52] [ 3]  / answers: 1 / hits: 61449  / 13 Years ago, thu, september 15, 2011, 12:00:00

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?



The


More From » jquery

 Answers
7

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); }
});


EDIT: Looks like it can't be done with JSONP. Modify HTTP Headers for a JSONP request


[#90086] Tuesday, September 13, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadon

Total Points: 488
Total Questions: 105
Total Answers: 105

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;