1

This was a great help to describing what is and how to make jsonp requests. https://stackoverflow.com/a/6879319/371137

I, however, also need to change the Accept value in the request header to 'application/javascript' so my 3rd party server will respond correctly.

There are lots of SO answers pertaining to setting the header values (including Pass accepts header parameter to jquery ajax) w/ the API, but none seem to be in conjunction with "jsonp".

I can't seem to figure out from jQuery's documentation how to actually alter the Accept header value when using datatype "jsonp".

beforeSend does nothing. "accepts" does nothing. "headers" seems to be ignored.

I can't even seem to set any custom headers at all.

No matter what i do the Accept header value is always '/'.

Any help would be appreciated.

Kirby
  • 1,980
  • 3
  • 21
  • 33
  • Possible duplicate of [Pass accepts header parameter to jquery ajax](https://stackoverflow.com/questions/12347211/pass-accepts-header-parameter-to-jquery-ajax) – erik258 Dec 29 '17 at 18:45
  • So i think the difference is with datatype: "jsonp" does somethings to the headers behind the scenes. ?? – Kirby Dec 29 '17 at 18:48
  • Agreed, not a dup. – erik258 Dec 29 '17 at 20:30

1 Answers1

2

No. JSONP requests are actually script requests(why the json is wrapped in function) which don't allow headers to be added

Similarly they can't be use for methods like POST

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • Looks to me like this is the best answer. However, I also don't see why this request would need to be JSONP. From what I can tell (https://stackoverflow.com/questions/3839966/can-anyone-explain-what-jsonp-is-in-layman-terms) with the advent of CORS there's really no benefit to JSONP, right? – erik258 Dec 29 '17 at 20:29
  • @DanFarrell agree with that. JSONP is now fairly outdated – charlietfl Dec 29 '17 at 20:30
  • I'm actually less familiar w/ JSONP than CORS.. but i was having continual issues w/ pre-flight requests from said 3rd party api. They had previously supported jsonp and made some code changes that now returns applicatoin/json in the response header... this seemed to break my legacy jsonp code. I think the answer is ... move to CORS and solve the preflight problem. I really appreciate both of your's help. – Kirby Dec 31 '17 at 00:24
  • Yes...if you control the endpoint that serves the json. If you don't ... use a proxy on a server you do control to make the request – charlietfl Dec 31 '17 at 00:29