setRequestHeader does not work in JSONP using jQuery

后端 未结 2 1713
情歌与酒
情歌与酒 2020-12-20 09:13

I am building an iPhone app using jQuery Mobile, jQuery 1.7.2, and PhoneGap

trying to get a JSONP from ASP.NET RESTful web service using this code, problem that I ne

2条回答
  •  隐瞒了意图╮
    2020-12-20 09:40

    A JSONP request does not use an actual ajax call where you can control the http request.

    Instead, it injects a script tag into your page and the browser then requests that script src file. The resulting script that is returned executes and communicates back it's result via that javascript execution (calling a callback function). Because the request is generated via a script tag insertion and not a direct ajax call, there is no ability to set request headers on a JSONP request.

    If your request is cross domain, then JSONP is your only mechanism.

    If your request is the same origin as the page (not cross domain), then you could restructure your request to be an actual ajax call that returns JSON data. If you did that, you could set request headers on the ajax call.

提交回复
热议问题