From 3733e7847855c59eedcf13937eb951c01990dc39 Mon Sep 17 00:00:00 2001 From: "Fabio M. Costa" Date: Sun, 5 Sep 2010 23:38:04 -0300 Subject: [PATCH] Request now forces the response to be parsed correctly. If the response header is not text/xml responseXML comes empty on firefox and on IE it contains an incorrect XML document. This fixes both behaviors. --- Source/Request/Request.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/Request/Request.js b/Source/Request/Request.js index c651d44a..fcb25013 100644 --- a/Source/Request/Request.js +++ b/Source/Request/Request.js @@ -15,7 +15,7 @@ provides: Request */ -(function(){ +(function(global){ var progressSupport = ('onprogress' in new Browser.Request); @@ -69,7 +69,10 @@ var Request = this.Request = new Class({ }.bind(this)); this.xhr.onreadystatechange = function(){}; clearTimeout(this.timer); - this.response = {text: (this.xhr.responseText || ''), xml: this.xhr.responseXML}; + + var text = this.xhr.responseText || '', xml = this.xhr.responseXML; + if (text && (!xml || !(xml && xml.documentElement))) xml = this.parseXML(text); // forces xml parsing + this.response = {text: text, xml: xml}; if (this.options.isSuccess.call(this, this.status)) this.success(this.response.text, this.response.xml); else @@ -137,7 +140,31 @@ var Request = this.Request = new Class({ } return false; }, + + parseXML: (function(){ + if (global.DOMParser){ + var domParser = new DOMParser(); + return function(text){ + return domParser.parseFromString(text, 'text/xml'); + }; + } + var xml = Function.attempt(function(){ + return new ActiveXObject('MSXML2.DOMDocument'); + }, function(){ + return new ActiveXObject('Microsoft.XMLDOM'); + }); + if (xml) xml.async = 'false'; + + return function(text){ + if (xml){ + xml.loadXML(text); + return xml; + } + return null; + }; + })(), + send: function(options){ if (!this.check(options)) return this; @@ -234,7 +261,7 @@ var methods = {}; Request.implement(methods); -})(); +})(window || this); Element.Properties.send = { -- 2.11.4.GIT