[Pkg-javascript-commits] [sockjs-client] 364/434: #51 - try using XMLHttpRequest instead of XMLHTTP one
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:25 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 429343bcc229564e0adbafbcea3b575a7fbc9a5e
Author: Marek Majkowski <majek04 at gmail.com>
Date: Wed Mar 7 13:17:49 2012 +0000
#51 - try using XMLHttpRequest instead of XMLHTTP one
---
lib/dom2.js | 23 ++++++++++++++++-------
tests/html/src/domtests.coffee | 2 +-
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/lib/dom2.js b/lib/dom2.js
index b49fbd5..2613e92 100644
--- a/lib/dom2.js
+++ b/lib/dom2.js
@@ -7,13 +7,19 @@ XHRObject.prototype = new EventEmitter(['chunk', 'finish']);
XHRObject.prototype._start = function(method, url, payload, opts) {
var that = this;
+
try {
- that.xhr = new _window.ActiveXObject('Microsoft.XMLHTTP');
- // IE caches POSTs
- url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
+ that.xhr = new XMLHttpRequest();
} catch(x) {};
+
if (!that.xhr) {
- that.xhr = new XMLHttpRequest();
+ try {
+ that.xhr = new _window.ActiveXObject('Microsoft.XMLHTTP');
+ } catch(x) {};
+ }
+ if (_window.ActiveXObject || _window.XDomainRequest) {
+ // IE8 caches even POSTs
+ url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
}
// Explorer tends to keep connection open, even after the
@@ -37,12 +43,15 @@ XHRObject.prototype._start = function(method, url, payload, opts) {
var x = that.xhr;
switch (x.readyState) {
case 3:
- // IE doesn't like peeking into responseText or status on
- // XHR and readystate=3
+ // IE doesn't like peeking into responseText or status
+ // on Microsoft.XMLHTTP and readystate=3
try {
var status = x.status;
var text = x.responseText;
- that.emit('chunk', status, text);
+ // IE does return readystate == 3 for 404 answers.
+ if (text.length > 0) {
+ that.emit('chunk', status, text);
+ }
} catch (x) {};
break;
case 4:
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index c1ceac1..2894217 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -118,7 +118,7 @@ test_wrong_url = (name, url, statuses) ->
expect(2)
x = new u[name]('GET', url, null)
x.onchunk = ->
- ok(false)
+ ok(false, "chunk shall not be received")
x.onfinish = (status, text) ->
ok(u.arrIndexOf(statuses, status) isnt -1)
equal(text, '')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list