我需要从网站向托管在另一个域中的 REST Web 服务发出 AJAX 请求。
尽管这在 Internet Explorer 中运行良好,但其他浏览器(例如 Mozilla 和 Google Chrome)施加了更严格的安全限制,禁止跨站点 AJAX 请求。
问题是我无法控制域或托管站点的 Web 服务器。这意味着我的 REST Web 服务必须在其他地方运行,并且我无法实施任何重定向机制。
下面是进行异步调用的 JavaScript 代码:
var serviceUrl = "http://myservicedomain";
var payload = "<myRequest><content>Some content</content></myRequest>";
var request = new XMLHttpRequest();
request.open("POST", serviceUrl, true); // <-- This fails in Mozilla Firefox amongst other browsers
request.setRequestHeader("Content-type", "text/xml");
request.send(payload);
我怎样才能在 Internet Explorer 以外的其他浏览器中进行这项工作?