我按照下面的 Microsoft 标准在请求中添加了变量,var openRetVal 和 var sendRetVal...奇怪的是,他们没有得到任何返回的内容,所以 Microsoft 在他们自己的文档中撒了谎吗?
我正在处理 ajax 请求,和往常一样,IE 是一个很难使用的样本。我发现我可以执行 XDR,而不是执行 AJAX 请求。我在 Chrome 中的代码可以工作,所以我知道目标服务器正在工作,并且在成功请求后会执行预期发生的操作。下面是我的 XDR 代码段。
if ($.browser.msie && window.XDomainRequest) {
var xdr = new XDomainRequest();
//var webstring = location.protocol +"//"+ location.host +"/" + WEBSERVICE_URL + "/test";
//WEBSERVICE_URL = "webservices/FormDesigner.svc";
var webstring = WEBSERVICE_URL + "/test";
var openRetVal = xdr.open("GET", webstring); //added this var as it supposidly gets a return value from the function call.
xdr.onload = function () {
var JSON = $.parseJSON(xdr.responseText);
if (JSON == null || typeof (JSON) == 'undefined') {
JSON = $.parseJSON(data.firstChild.textContent);
}
//below is my onsuccess call which is called by both successes for IE and NON-IE processes allowing all stuff to be piped into 1 call.
ajax_success(JSON);
};
xdr.ontimeout = function () {
alert("XDR Error. Timeout");
}
xdr.onerror = function () {
alert("XDR Error. Unable to do a Cross Domain Server Request.");
};
var sentRetVal = xdr.send(); //added this var as the function is suppose to return success or error as per microsoft.
}
它总是返回 onerror,这自然不是我的目标。我目前正在对同一域内的某些内容执行 ping 操作以进行测试,这就是为什么没有其他内容的原因。就像我说的,到目前为止它可以与其他浏览器一起使用...是否有我不知道的格式不正确?此测试请求也没有提交任何数据。
最佳答案
如果您已经使用 jQuery,只需将 jQuery 用于所有浏览器,那么在 IE 中就不会有任何问题。
关于javascript - Internet Explorer跨域请求无法正常工作并且MS没有给出onerror推理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11416175/