Fixes cross domain XHR on IE8/9

This commit is contained in:
Guillermo Rauch
2011-06-20 06:16:50 -03:00
parent 90641c1f34
commit 3fda1e6d35
2 changed files with 26 additions and 7 deletions

View File

@@ -64,7 +64,7 @@
function stateChange () {
if (this.readyState == 4) {
this.onreadystatechange = this.onload = empty;
this.onreadystatechange = empty;
if (this.status == 200) {
self.onData(this.responseText);
@@ -73,13 +73,21 @@
self.onClose();
}
}
}
};
function onload () {
this.onload = empty;
self.onData(this.responseText);
self.get();
};
this.xhr = this.request();
if (window.XDomainRequest && this.xhr instanceof XDomainRequest) {
this.xhr.onload = stateChange;
this.xhr.onerror = function (e) { self.onError(e); };
this.xhr.onload = onload;
this.xhr.onerror = function (e) {
self.onError(e);
};
} else {
this.xhr.onreadystatechange = stateChange;
}

View File

@@ -103,7 +103,7 @@
function stateChange () {
if (this.readyState == 4) {
this.onreadystatechange = this.onload = empty;
this.onreadystatechange = empty;
self.posting = false;
if (this.status == 200){
@@ -114,10 +114,19 @@
}
}
function onload () {
this.onload = empty;
self.posting = false;
self.checkSend();
};
this.sendXHR = this.request('POST');
if (window.XDomainRequest && this.xhr instanceof XDomainRequest) {
this.sendXHR.onload = stateChange;
this.sendXHR.onload = onload;
this.sendXHR.onerror = function (e) {
self.onError(e);
};
} else {
this.sendXHR.onreadystatechange = stateChange;
}
@@ -171,7 +180,9 @@
req.setRequestHeader('Content-type', 'text/plain');
} else {
// XDomainRequest
req.contentType = 'text/plain';
try {
req.contentType = 'text/plain';
} catch (e) {}
}
}