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

pen*_*ake 5 javascript http xmlhttprequest cors xdomainrequest

对于XMLHttpRequest,它非常简单:

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

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

Kim*_*m T 0

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

header('Content-type: application/json');
Run Code Online (Sandbox Code Playgroud)

如果这是不可能的,那么您可以创建一个本地代理脚本,该脚本使用正确的标头镜像您的跨域脚本