简体   繁体   English

如何设置 XDomainRequest 对象的内容类型?

[英]How can I set the content-type of XDomainRequest object?

for XMLHttpRequest it is pretty easy: XMLHttpRequest 很简单:

var xhr = new XMLHttpRequest();
xhr.open('POST', MyUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json')

But how do I achieve this for XDomainRequest?但是我如何为 XDomainRequest 实现这一点?

It's not possible to override the XMLHttpRequest content-type.不可能覆盖 XMLHttpRequest 内容类型。 You should set it correctly on the server eg for php:您应该在服务器上正确设置它,例如对于 php:

header('Content-type: application/json');

If this is not possible, then you can create a local proxy script which mirrors your crossdomain script with the correct header如果这是不可能的,那么您可以创建一个本地代理脚本,该脚本使用正确的标头镜像您的跨域脚本

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

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