SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool getElementsByTagName problems in FireFox

    Please tell me why this does not work in FF. I need to sleep.

    See it in action here: http://www.vinhboy.com/ffff.php

    Code:
    <html>
    <head>
    </head>
    
    <body>
    
    <script type="text/javascript">
    var xmlDoc;
    function loadXML()
    {
    // code for IE
    if (window.ActiveXObject)
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load("test2.php");
      getmessage();
      }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation &&
    document.implementation.createDocument)
      {
      xmlDoc=document.implementation.createDocument("","",null);
      xmlDoc.load("test2.php");
      xmlDoc.onload = getmessage();
      }
    else
      {
      alert('Your browser cannot handle this script');
      }
    }
    
    function getmessage()
    {
    for (i=0;i<(xmlDoc.getElementsByTagName("title").length);i++)
    {
    text = xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue;
    document.write(text);
    document.write("<br />");
    }
    }
    
    loadXML();
    
    </script>
    
    </body>
    </html>

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing this line:

    xmlDoc.onload = getmessage();

    to this:

    xmlDoc.onload = getmessage;

    The parens cause the function to be "called". You want to assign a reference to the function to "xmlDoc.onload", not the return value from calling the function.


  3. #3
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply. tried it but it didnt work.

    i even tried the XMLHTTPRequest method to load my XML, but for some reason firefox can never get the tagname...

  4. #4
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turns out the test2.php, which was loading an external xml file for me, could not be used.

    Instead, I took the content of test2.php and dumped it into a test.xml and that worked!

    Can someone enlighten me on why an "xml" extension works versus a "php" extension and how I can get around this, since I am interested in keeping my PHP file. Note: Both files had the same exact content!

    Thanks. Vinh

  5. #5
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the php is xml you should also send correct header
    Code:
    header("Content-type: text/xml");

  6. #6
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks alot, that did the trick.


Bookmarks

Posting Permissions

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