From: sheldonlg on
First, I know just a little Javascript -- enough to be dangerous :-).

I have come across a problem that Firefox discards all but the first
chunk of 4096 on a return from an AJAX call. I searched Google and
found that it is a known problem and found a suggested solution. I
tried it but it doesn't work. I am asking here on what I have to do to
my code to make it work transparent to the particular browser. Here is
the pertinent code segment. The getNodeText function was the suggestion
I found on Google. The commented line in handleResponse is what was
there before (and also only got 4096).


function getNodeText(xmlNode) {
if(!xmlNode) return '';
if(typeof(xmlNode.textContent) != "undefined")
return xmlNode.textContent;
return xmlNode.firstChild.nodeValue;
}

function handleResponse(pObjRequest) {
if (pObjRequest.readyState==4) {
if (pObjRequest.status==200) {
//resp = pObjRequest.responseText;
resp = getNodeText(pObjRequest);
condition_code = parseMultiXML(resp);
pObjRequest=null; // dispose of the now un-needed object.
}
}
}

Any help would be appreciated.
From: Stefan Weiss on
On 30/10/09 00:13, sheldonlg wrote:
> I have come across a problem that Firefox discards all but the first
> chunk of 4096 on a return from an AJAX call. I searched Google and
> found that it is a known problem and found a suggested solution. I
> tried it but it doesn't work. I am asking here on what I have to do to
> my code to make it work transparent to the particular browser. Here is
> the pertinent code segment. The getNodeText function was the suggestion
> I found on Google. The commented line in handleResponse is what was
> there before (and also only got 4096).

Call normalizeDocument() on the response XML.


cheers,
stefan
From: Stefan Weiss on
On 30/10/09 00:19, Stefan Weiss wrote:
> On 30/10/09 00:13, sheldonlg wrote:
>> I have come across a problem that Firefox discards all but the first
>> chunk of 4096 on a return from an AJAX call. I searched Google and
>> found that it is a known problem and found a suggested solution. I
>> tried it but it doesn't work. I am asking here on what I have to do to
>> my code to make it work transparent to the particular browser. Here is
>> the pertinent code segment. The getNodeText function was the suggestion
>> I found on Google. The commented line in handleResponse is what was
>> there before (and also only got 4096).
>
> Call normalizeDocument() on the response XML.

Sorry, that was probably too terse to be useful. The normalizeDocument()
method should be called on the responseXML's document element - if the
method is available. Here's some example code; 'xhr' is the
XMLHttpRequest object, and error handling has been omitted for clarity:

var docEle = xhr.responseXML.documentElement;
if (typeof docEle.normalizeDocument == "function") {
docEle.normalizeDocument();
}

This will join adjacent text nodes into single text nodes, avoiding the
4K limit in Mozilla's XML parser. It will also perform other
normalizations; the full description is available here:
<http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-normalizeDocument>


HTH,
stefan
From: Martin Honnen on
Stefan Weiss wrote:

> Sorry, that was probably too terse to be useful. The normalizeDocument()
> method should be called on the responseXML's document element - if the
> method is available. Here's some example code; 'xhr' is the
> XMLHttpRequest object, and error handling has been omitted for clarity:
>
> var docEle = xhr.responseXML.documentElement;
> if (typeof docEle.normalizeDocument == "function") {
> docEle.normalizeDocument();
> }

normalizeDocument is a method of the Document interface, not of the
Element interface so you will never be able to call it on the
documentElement.

And normalizeDocument is DOM Level 3 while the method 'normalize' is DOM
Level 1 and does all you need so doing
xhr.responseXML.documentElement.normalize()
should suffice and have better support than the normalizeDocument method.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
From: Stefan Weiss on
On 31/10/09 13:40, Martin Honnen wrote:
> Stefan Weiss wrote:
>
>> Sorry, that was probably too terse to be useful. The normalizeDocument()
>> method should be called on the responseXML's document element - if the
>> method is available. Here's some example code; 'xhr' is the
>> XMLHttpRequest object, and error handling has been omitted for clarity:
>>
>> var docEle = xhr.responseXML.documentElement;
>> if (typeof docEle.normalizeDocument == "function") {
>> docEle.normalizeDocument();
>> }
>
> normalizeDocument is a method of the Document interface, not of the
> Element interface so you will never be able to call it on the
> documentElement.
>
> And normalizeDocument is DOM Level 3 while the method 'normalize' is DOM
> Level 1 and does all you need so doing
> xhr.responseXML.documentElement.normalize()
> should suffice and have better support than the normalizeDocument method.

Thanks, I got that mixed up when I tried to simplify existing code. I
wasn't aware that normalize() was better supported; very interesting.


cheers,
stefan