我不确定这是同一个问题,但就我而言,所有这些都需要设置:onerror; 进行中 超时 和加载。这里是一些讨论该问题的参考:
- http://social.msdn.microsoft.com/Forums/ie/zh-CN/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-未指定处理程序
- http://cypressnorth.com/programming/internet-explorer-aborting-ajax-requests-fixed/
- http://rudovsky.blogspot.com/2012/09/microsoft-shit-xdomainrequest.html
- https://github.com/faye/faye/pull/98
还有很多其他的。他们的建议解决方案分散,有时矛盾。例如,建议将xdr.send调用包装在setTimeout中。
我看到的行为通过为每个事件处理函数添加非空白主体而消失了。我不确定是否全部必要。该setTimeout的包装肯定 不是 必要的。
一条可能不相关的信息:在我的情况下,我决定将每个处理程序绑定到“
this”对象。我还添加了函数实现,以防止编译器将它们全部分配给同一空函数。我的代码使用的是GET,而不是POST。YMMV。
您的代码使一个处理程序保持不变:
if (window.XDomainRequest) // Check whether the browser supports XDR.{ xdr = new XDomainRequest(); // Create a new XDR object. if (xdr) { xdr.timeout = 3000;//Set the timeout time to 3 second. xdr.onload = function () { alert("Success"); }; xdr.onerror = function () { alert("Error"); }; xdr.ontimeout = function () { alert("Error"); }; // this also needs to be set xdr.onprogress = function() { window.console.log('progress'); }; xdr.open("post", urlSearch); xdr.send(); }}else { $.ajax({ url: urlSearch, type: 'POST', dataType: 'json', timeout: 3000, success: function (data) { alert("Success"); }, error: function () { alert("Error"); } });}


