changeset 352:0b4fe47e648d

mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 02 Apr 2011 04:27:43 +0500
parents 85d3c04c64f6
children 8ef36af30181
files mod_json_streams/strophe.jsonstreams.js
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_json_streams/strophe.jsonstreams.js	Sat Apr 02 03:11:22 2011 +0500
+++ b/mod_json_streams/strophe.jsonstreams.js	Sat Apr 02 04:27:43 2011 +0500
@@ -39,7 +39,8 @@
                 		return _xhr.send(data);
                 	}
                 };
-                xhr.onreadystatechange = _xhr.onreadystatechange;
+                var req = this;
+                xhr.onreadystatechange = this.func.bind(null, this);
                 _xhr.onreadystatechange = function() {
                 	xhr.readyState = _xhr.readyState;
                 	if (xhr.readyState != 4) {
@@ -50,7 +51,9 @@
 	                	xhr.status = _xhr.status;
 	               		xhr.responseText = _xhr.responseText;
 	               		xhr.responseXML = _xhr.responseXML;
-	                	if (_xhr.responseText && !_xhr.responseXML) {
+	                	if (_xhr.responseText && !(_xhr.responseXML
+	                			&& _xhr.responseXML.documentElement
+	                			&& _xhr.responseXML.documentElement.tagName != "parsererror")) {
 	                		var data = JSON.parse(_xhr.responseText);
 	                		if (data && data.s) {
 	                			xhr.responseText = data.s;
@@ -58,7 +61,7 @@
 	                		}
 	                	}
 	                }
-                	if (xhr.onreadystatechange) { xhr.onreadystatechange(); }
+                	if ("function" == typeof xhr.onreadystatechange) { xhr.onreadystatechange(req); }
                 }
                 return xhr;
             };