【发布时间】:2015-08-26 13:16:50
【问题描述】:
我在我的脚本中使用$.ajax() 函数,该函数从其他域调用Web 服务。但我在 IE 中遇到错误。然后经过研究,我知道错误是由于 Internet Explorer 默认设置为"Access data sources across domains" to "prompt"。如何使用脚本设置"Enable"..?
代码:
var serviceURL = "https://www.other-domain.com/webservice/showbills?billID=12458";
if ($.browser.msie && window.XDomainRequest) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var data = xhr.responseText;
var xmlDoc = $.parseXML(data); // then parse into xml
var xml = $(xmlDoc); // create doc
console.log(xml);
// show bill here in table.
}
}
xhr.open('POST', serviceURL, true);
xhr.send();
} else {
$.ajax({
type: "POST",
url: serviceURL,
dataType: "text",
crossOrigin: true,
crossDomain: true,
success: function (data) {
var xmlDoc = $.parseXML(data); // then parse into xml
var xml = $(xmlDoc);// create doc
console.log(xml);
// show bill here in table.
}
});
}
这在浏览器中出现错误。
我收到SEC7120: Origin http://localhost:8080 not found in Access-Control-Allow-Origin header 和SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied
【问题讨论】:
标签: javascript ajax internet-explorer browser