...

View Full Version : IE Error getting XML result



carlitos_way
12-15-2008, 12:55 PM
Hi All,

I'm working on a web-app that, by using ajax, make a request to a server and receives an XML that is used to draw a table on the browser, containing all the result received.

The function I built works greatly on FF, but at the moment gives me a problem on IE6/7.

I think, but I'm not sure, that the problem is that my javascript starts parsing the xml before all the response is downloaded, causing me the error.
I think this because at the start of my function I make a 'result.getElementsByTagName('Result')' and I check for its length, receiving '0' as length; and when accessing 'resultNode[0].getAttribute('xxxxxx')' it throws me an error:


function BuildXMLResults(){
var destination = 'ErrorResult'; // dove mostrare il valore di errore
if(reqXML.readyState == 4){
if(reqXML.status == 200){
var result = reqXML.responseXML;

var errorValue = '', responseValue = '';
var resultNode = result.getElementsByTagName('Result');

if (resultNode) {
alert('length: ' + resultNode.length + ' error: ' + resultNode[0].getAttribute('Error'));
errorValue = resultNode[0].getAttribute('Error');
responseValue = resultNode[0].firstChild.nodeValue;
}

errorValue == 0?$(destination).innerHTML = 'Operazione eseguita correttamente.':$(destination).innerHTML = responseValue;

...
...


I just used Fiddlr to check for the integrity of the response, and it says that the xml received is correct. This is the sample xml I receive:

<?xml version="1.0"?>
<DocWeaver Version="3.1.86b"><Result Error="0">Operazione eseguita correttamente.</Result><Values>.....</Values></DocWeaver>

As I was thinking that the problem was the result being parsed before being completely downloaded, I choosed to make a synchronous call to get it (instead of making an asynchronous one), but after that I still get the same error...

Can you give me any idea of what could be or what I should look for to understand the problem?

Thanks
regards
CB

dk01
12-15-2008, 10:18 PM
Not sure about what might be going on. Can you post your load xml function?

I would try adding a random number to the end of the ajax url to make sure to force IE to refresh the xml. IE has wicked amounts of caching and a random number is needed many times.

carlitos_way
12-16-2008, 12:04 PM
I made a few tests and noticed that sometimes it works, while other times it doesn't.

This is an example in which it does not work:

my js (in a function to try reading the response locally):

function parseXML(fileXML)
{
var destination = 'ErrorResult';
var urlXML = 'http://localhost:8085/docweaverweb/xml/' + fileXML;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
} catch(e) {
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
} catch(e) {
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load(urlXML);

var result = xmlDoc;

var errorValue = '', responseValue = '';
var resultNode = result.getElementsByTagName('Result');

if (resultNode) {
try {
responseValue = resultNode[0].getAttribute('Error');
alert('length: ' + resultNode.length + ' error: ' + responseValue);
errorValue = resultNode[0].getAttribute('Error');
responseValue = resultNode[0].firstChild.nodeValue;
} catch(e) {
// e.name / e.message
alert('Errore: ' + e.name + ' - Messaggio: ' + e.message);
return true;
}
}
errorValue == 0?$(destination).innerHTML = 'Operazione eseguita correttamente.':$(destination).innerHTML = responseValue;
}

the xml received:
see the document attached and rename it back to xml

Maybe there's any character that gives problem... I'll debug the server response to see if I find anything..

carlitos_way
12-19-2008, 05:41 PM
my solution: I found that the XML was well formed but not valid, so maybe this was the problem with IE (I needed to put a Doctype to the xml)

anyway, I choosed to modify the servlet and receive the data in JSON format, and now it's working on all browsers..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum