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

时间:2013-02-27 13:30:26

标签: javascript http xmlhttprequest cors xdomainrequest

对于XMLHttpRequest来说非常简单:

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

但是我如何为XDomainRequest实现这个目标?

1 个答案:

答案 0 :(得分:0)

无法覆盖XMLHttpRequest内容类型。您应该在服务器上正确设置它,例如对于php:

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

如果无法做到这一点,那么您可以创建一个本地代理脚本,该脚本使用正确的标头镜像您的跨域脚本

相关问题