如何以编程方式启用浏览器跨域数据源。? [英] how to programmatically enable data sources across domains in browser.?
问题描述
我使用 $。阿贾克斯()
功能。但我在IE收到错误。然后做研究之后,我才知道错误是由默认设置,应尽快到到Internet Explorer 跨域访问数据源到提示
。如何设置启用
使用脚本..?
I am using $.ajax()
function in my script which is calling web service from other domain. but I am getting error in IE. Then after doing research, I came to know error was coming due to Internet Explorer by default set "Access data sources across domains" to "prompt"
. How to set it "Enable"
using script..?
code:
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:产地HTTP://本地主机:8080访问控制允许来源标题
和 SCRIPT7002未找到:XMLHtt prequest:网络错误0X80070005,访问被拒绝
推荐答案
微软创造了在Internet Explorer跨域AJAX请求,称XDomainRequest自己的解决方案。
Microsoft has created its own solution for cross domain AJAX requests in Internet Explorer, called XDomainRequest.
有一个jQuery插件来支持这一点: https://github.com/MoonScript/ jQuery的-ajaxTransport-XDomainRequest
There is a plugin for jQuery to support this: https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
您只需要包括jQuery的后包括此脚本,然后它应该工作。
You just have to include this script after including jQuery and then it should work.
这篇关于如何以编程方式启用浏览器跨域数据源。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!