iosrockstar / jquery-jsonp

Automatically exported from code.google.com/p/jquery-jsonp
0 stars 0 forks source link

Cannot use the setRequestHeader("User-Agent", "Anything") function at the beforeSend parameter #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? Using this:
    beforeSend: function(req) {
      req.setRequestHeader('User-Agent', 'Anything');
    },
This is valid for $.ajax, an example of it's usage can be found at: 
http://docs.jquery.com/Tutorials:Using_AjaxPro

What is the expected output? What do you see instead?
Expected outcome is sending the request with User-Agent set to "Anything", 
current outcome is a Firebug error that setRequestHeader function doesn't 
exist.

It seems that $.jsonp does not use xhr requests, that's why the function 
does not work. Is there any work around?

Thank you

Original issue reported on code.google.com by amer...@gmail.com on 4 Nov 2009 at 7:14

GoogleCodeExporter commented 8 years ago
No there is workaround. At its core, jQuery.jsonp is still an ugly script tag 
hack
and no access to HTTP headers is possible. The documentation is quite clear on 
the
fact that you never get to toy with an xhr object but an xoptions object. FYI, 
$.ajax
with dataType "jsonp" does not even call beforeSend to begin with. In $.jsonp, 
it's
more of a convenience to check parameters or to make a pre-emptive abort.

Original comment by aubourg.julian on 5 Nov 2009 at 1:30