# HG changeset patch # User Waqas Hussain # Date 1301700463 -18000 # Node ID 0b4fe47e648d31e44281e4588e0f2b901609625e # Parent 85d3c04c64f65bc7b92e577d298d8ee648d6d261 mod_json_streams/strophe.jsonstreams.js: Fix some compatability issues. diff -r 85d3c04c64f6 -r 0b4fe47e648d mod_json_streams/strophe.jsonstreams.js --- 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; };