RE: [XHR] Status Update

Jonas,

With the code below, I have no problem doing this in Firefox. Notes:
- asyncXHR is a typical XHR wrapper function, not included here for
brevity.
- The key statement below is:
	document.getElementById("text").innerHTML = "Headers:<br>" +
hdrs + "<br/>" + xhr.responseText;
	With this, Firefox correctly renders the retrieved HTML content
into the element "text".

function gotResponse(xhr) {
	var extref = document.getElementById("extref");
	extref.innerHTML = "";	
	extref.setAttribute('src', "");
	var hdrs = xhr.getAllResponseHeaders();
	var type = xhr.getResponseHeader("Content-Type");
	if (type === "text/plain") {
		document.getElementById("text").innerHTML =
"Headers:<br>" + hdrs + "<br/><pre>" + xhr.responseText + "</pre>";
	}    
	else {
		document.getElementById("text").innerHTML =
"Headers:<br>" + hdrs + "<br/>" + xhr.responseText;
	}
}

function loadFile(url,inline) {
	var encurl = encodeURI(url);
	if (inline) {
		document.getElementById("text").innerHTML = "loadFile: "
+ url;
		asyncXHR('GET',encurl,"",'*/*',"",gotResponse);
	}
	else {
		var extref = document.getElementById("extref");
		document.getElementById("text").innerHTML = "loadFile: "
+ url + "<br>File should appear below";
		extref.setAttribute('src', encurl);		
	}
}

Thanks, 
Bryan Sullivan | AT&T


-----Original Message-----
From: Jonas Sicking [mailto:jonas@sicking.cc] 
Sent: Monday, August 09, 2010 5:23 PM
To: SULLIVAN, BRYAN L (ATTCINW)
Cc: Anne van Kesteren; WebApps WG
Subject: Re: [XHR] Status Update

On Mon, Aug 9, 2010 at 5:13 PM, SULLIVAN, BRYAN L (ATTCINW)
<BS3131@att.com> wrote:
> Well at least it works in Firefox, Safari, Opera, and Chrome.
>
> With that broad support, I imagine that removing this defacto feature
in
> XHR L2 would cause a lot of heartburn for developers who probably rely
> upon it today.

This is not correct. I can't speak for the other browsers, but Firefox
does not support loading HTML documents using XMLHttpRequest. We never
hook up any other type of parser than an XML parser. And if the
Content-Type of the response is "text/html" we don't hook up any
parser at all.

/ Jonas

Received on Tuesday, 10 August 2010 03:19:48 UTC