Set headers using jQuery.ajax and JSONP?

I am trying to access google docs using jQuery. Here is what I still have:

var token = "my-auth-token"; $.ajax({ url: "http://docs.google.com/feeds/documents/private/full?max-results=1&alt=json", dataType: 'jsonp', beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "GoogleLogin auth=" + token); }, success: function(data, textStatus, XMLHttpRequest) { }, error: function(XMLHttpRequest, textStatus, errorThrown) { } }); 

This does not allow me to set headers if I install dataType in jsonp (from Make queries to Ajax cross domain using jQuery ). If I leave jsonp , I cannot complete the cross-domain request. If I use jQuery.getJSON , I cannot pass any headers ...

Is there a way to define custom headers when creating a cross-domain ajax request (in jQuery)?

+43
jquery ajax header cross-domain
Jun 18 '10 at 21:51
source share
1 answer

It's impossible.

A JSONP request works by creating a <script> element with its src attribute set to the request URL.
You cannot add your own headers to the HTTP request sent by the <script> element.

+64
Jun 18 '10 at 21:55
source share



All Articles