javascript - Jquery Ajax Does Not Send Accept Header -


here's ajax call:

function fetchaccount(email, callback) {   $.ajax({     url: "http://example.com/",     jsonp: "callback",     datatype: 'jsonp',     type: 'get',     async: false,     headers: {"accept" : "application/javascript; charset=utf-8"},     success: function(data) {       appstate.user = data;       appstate.viewstate = appstates.content_view;       appstore.persisttolocalstorage();       callback();          },     error: function(xhr, status, err) {       appstate.user = "";       appstate.viewstate = appstates.login_fail_view;       appstore.persisttolocalstorage();       callback();     }       }); }; 

my server isnt returning jsonp because accept header isn't set properly. when use "modify headers" google chrome extension manually inject "accept" "application/javascript; charset=utf-8" server responds jsonp fine.

i captured request header , expected, "accept" isnt being set properly:

get /api/accounts/myemail@gmail.com?callback=jquery22009572079558856785_1454040030107&_=1454040030108 http/1.1 host: www.example.com connection: keep-alive accept: */* user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/48.0.2564.97 safari/537.36 accept-encoding: gzip, deflate, sdch accept-language: en-us,en;q=0.8,et;q=0.6 

what's going on here - how can set accept header? seems simple...

the problem i'm expecting wrong thing. according this jquery bug report (https://bugs.jquery.com/ticket/7694) when jsonp you're not firing xhr can't control headers.


Comments