从IE不一致阿贾克斯(XDR)响应 [英] Inconsistent ajax (XDR) response from IE
问题描述
我在做的就是通过IE插件注入到每一个网页的iframe一个Ajax请求。我使用的是IE浏览器的跨域请求因为jQuery的Ajax失败对于IE浏览器。这工作的时间在IE8和放大器75%; 9.其他25%, xdr.onload
不甚至引起火灾。
服务器PHP是做的工作...日志看起来完全相同时,的onload
不和不火。此外, xdr.onerror
不火无论是。
任何想法?
thisURL = "http://example.com/getmsg.php?cmd=getMessage&iid=ddeb2c1228&uurl=http%3A%2F%2Fwww.cnn.com%2F&t=" +的Math.random();
//使用Microsoft XDR
VAR XDR =新XDomainRequest();
xdr.open(GET,thisURL);
xdr.onload =功能(){
//这有时被称为,有时不是在IE
警报('INCONSISTENT ALERT);
回调(xdr.responseText);
};
xdr.send();
发现了问题,最后一分钟。在我来说,我需要指定一个超时值,即使请求不超时。为了正确调试XDR问题,我建议以下code,每一个警报,告诉你什么是您的code回事。正如我所说的,在我的情况下,它是一个缺少暂停
声明。但是,code以下应调试任何XDR问题:
VAR XDR =新XDomainRequest();
如果(XDR){
xdr.onerror =功能(){
//警报(XDR的onerror');
};
xdr.ontimeout =功能(){
//警报(XDR ontimeout');
};
xdr.onprogress =功能(){
//警报(XDR onprogress);
//警报(得到的答案:+ xdr.responseText);
};
xdr.onload =功能(){
//警报('onload事件'+ xdr.responseText);
回调(xdr.responseText);
};
xdr.timeout = 5000;
xdr.open(得,thisURL);
xdr.send();
} 其他 {
//警报(无法创建XDR');
}
I'm making an ajax request from an iframe that is injected onto every page via an IE plugin. I'm using IE's cross domain request because jQuery's ajax fails for IE. This works 75% of the time on IE8 & 9. The other 25%, the xdr.onload
doesn't even fire.
The server php is doing its job...the log looks identical for when onload
does and does not fire. Also, xdr.onerror
doesn't fire either.
Any ideas?
thisURL = "http://example.com/getmsg.php?cmd=getMessage&iid=ddeb2c1228&uurl=http%3A%2F%2Fwww.cnn.com%2F&t=" + Math.random();
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("GET", thisURL);
xdr.onload = function() {
// this is sometimes called, sometimes not in IE
alert('INCONSISTENT ALERT');
callback(xdr.responseText);
};
xdr.send();
Found out the issue last minute. In my case I needed to specify a timeout value, even though the requests were not timing out. In order to properly debug an XDR issue I'd suggest the following code, with each alert telling you what's going on with your code. As I said, in my case it was a missing timeout
declaration. But the code below should debug any XDR problems:
var xdr = new XDomainRequest();
if (xdr) {
xdr.onerror = function () {
// alert('xdr onerror');
};
xdr.ontimeout = function () {
// alert('xdr ontimeout');
};
xdr.onprogress = function () {
// alert("XDR onprogress");
// alert("Got: " + xdr.responseText);
};
xdr.onload = function() {
// alert('onload' + xdr.responseText);
callback(xdr.responseText);
};
xdr.timeout = 5000;
xdr.open("get", thisURL);
xdr.send();
} else {
// alert('failed to create xdr');
}
这篇关于从IE不一致阿贾克斯(XDR)响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!