Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    italy
    Posts
    94
    Thanks
    1
    Thanked 1 Time in 1 Post

    Exclamation IE Error getting XML result

    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:

    Code:
    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:
    Code:
    <?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
    Last edited by carlitos_way; 12-15-2008 at 03:08 PM.

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    italy
    Posts
    94
    Thanks
    1
    Thanked 1 Time in 1 Post
    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):
    Code:
    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..
    Attached Files Attached Files

  • #4
    New Coder
    Join Date
    Mar 2007
    Location
    italy
    Posts
    94
    Thanks
    1
    Thanked 1 Time in 1 Post
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •