Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the headers for angularjs $http.jsonp

I read the document.

but I think I must have misunderstood it.

$http.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {

I also have tried

$httpProvider.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {

I wanted to change the Accept to application/json

Neither work.

like image 637
Kim Stacks Avatar asked Oct 26 '13 06:10

Kim Stacks


1 Answers

There is no way to control headers sent by a browser while using JSONP. JSONP is a smart trick (or a hack, depending on how you see it...) that consist of inserting a <script> tag pointing to a server endpoint. Ultimately it is a browser who will decide which headers to sent while requesting scripts via <script> tag and you can't influence it.

More info here: Modify HTTP Headers for a JSONP request

like image 85
pkozlowski.opensource Avatar answered Oct 29 '22 18:10

pkozlowski.opensource