From 3fda1e6d35ea11a18b4d755ddab67d0463cc8deb Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Mon, 20 Jun 2011 06:16:50 -0300 Subject: [PATCH] Fixes cross domain XHR on IE8/9 --- lib/transports/xhr-polling.js | 16 ++++++++++++---- lib/transports/xhr.js | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/transports/xhr-polling.js b/lib/transports/xhr-polling.js index 764c60ea..447e3949 100644 --- a/lib/transports/xhr-polling.js +++ b/lib/transports/xhr-polling.js @@ -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; } diff --git a/lib/transports/xhr.js b/lib/transports/xhr.js index fe14d02d..e45f3336 100644 --- a/lib/transports/xhr.js +++ b/lib/transports/xhr.js @@ -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) {} } }