简体   繁体   English

使用JSONP时是否可以使用jQuery设置请求标头值?

[英]Is it possible to set a Request Header value with jQuery when using JSONP?

This was a great help to describing what is and how to make jsonp requests. 这对描述什么是以及如何发出jsonp请求很有帮助。 https://stackoverflow.com/a/6879319/371137 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. 但是,我还需要将请求标头中的Accept值更改为“ application / javascript”,这样我的第三方服务器才能正确响应。

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". 有很多关于通过 API设置标头值的SO答案(包括Pass接受标头参数到jquery ajax ),但似乎没有一个与“ jsonp”结合使用。

I can't seem to figure out from jQuery's documentation how to actually alter the Accept header value when using datatype "jsonp". 我似乎无法从jQuery的文档中弄清楚在使用数据类型“ jsonp”时如何实际更改Accept标头值。

beforeSend does nothing. beforeSend不执行任何操作。 "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 ' / '. 无论我做什么,Accept标头值始终为“ / ”。

Any help would be appreciated. 任何帮助,将不胜感激。

No. JSONP requests are actually script requests(why the json is wrapped in function) which don't allow headers to be added 否。JSONP请求实际上是脚本请求(为什么将json包装在函数中),因此不允许添加标头

Similarly they can't be use for methods like POST 同样,它们不能用于POST之类的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM