Mercurial > prosody-modules
comparison mod_json_streams/strophe.jsonstreams.js @ 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 | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
351:85d3c04c64f6 | 352:0b4fe47e648d |
---|---|
37 send: function(data) { | 37 send: function(data) { |
38 data = JSON.stringify({"s":data}); | 38 data = JSON.stringify({"s":data}); |
39 return _xhr.send(data); | 39 return _xhr.send(data); |
40 } | 40 } |
41 }; | 41 }; |
42 xhr.onreadystatechange = _xhr.onreadystatechange; | 42 var req = this; |
43 xhr.onreadystatechange = this.func.bind(null, this); | |
43 _xhr.onreadystatechange = function() { | 44 _xhr.onreadystatechange = function() { |
44 xhr.readyState = _xhr.readyState; | 45 xhr.readyState = _xhr.readyState; |
45 if (xhr.readyState != 4) { | 46 if (xhr.readyState != 4) { |
46 xhr.status = 0; | 47 xhr.status = 0; |
47 xhr.responseText = ""; | 48 xhr.responseText = ""; |
48 xhr.responseXML = null; | 49 xhr.responseXML = null; |
49 } else { | 50 } else { |
50 xhr.status = _xhr.status; | 51 xhr.status = _xhr.status; |
51 xhr.responseText = _xhr.responseText; | 52 xhr.responseText = _xhr.responseText; |
52 xhr.responseXML = _xhr.responseXML; | 53 xhr.responseXML = _xhr.responseXML; |
53 if (_xhr.responseText && !_xhr.responseXML) { | 54 if (_xhr.responseText && !(_xhr.responseXML |
55 && _xhr.responseXML.documentElement | |
56 && _xhr.responseXML.documentElement.tagName != "parsererror")) { | |
54 var data = JSON.parse(_xhr.responseText); | 57 var data = JSON.parse(_xhr.responseText); |
55 if (data && data.s) { | 58 if (data && data.s) { |
56 xhr.responseText = data.s; | 59 xhr.responseText = data.s; |
57 xhr.responseXML = parseXMLString(data.s); | 60 xhr.responseXML = parseXMLString(data.s); |
58 } | 61 } |
59 } | 62 } |
60 } | 63 } |
61 if (xhr.onreadystatechange) { xhr.onreadystatechange(); } | 64 if ("function" == typeof xhr.onreadystatechange) { xhr.onreadystatechange(req); } |
62 } | 65 } |
63 return xhr; | 66 return xhr; |
64 }; | 67 }; |
65 } else { | 68 } else { |
66 Strophe.error("jsonstreams plugin loaded, but JSON not found." + | 69 Strophe.error("jsonstreams plugin loaded, but JSON not found." + |