SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any reason Firefox would silently fail to open an XML with a .php extension?

    I have a dynamic xml file that has a php extension and echoes out the xml file from a mysql database.

    Everything worked fine in IE, but Firefox silently fails to load it without even throwing an exception/error.

    Even more oddly is that I made a php script to create the exact same file on the server with an xml extension, and changing nothing in the javascript except the filename to the xml version, it then works in firefox. It is driving me nuts. I would far rather use the php version instead of having to create the xml file everytime the database changes (I would rather have the code isolated to as few files as possible and not in all my db editing files as well)

    The xml file is at:
    http://www.thebrasse.com/lotro/lotroquestxml.xml

    The php file that loads fine in IE, but NOT in firefox (fails without error, returning an empty xmlDoc:
    http://www.thebrasse.com/lotro/lotroquestxml.php

    The php in the php file is exactly the same as the php used to make the xml, the only change is that one uses echo and one uses fopen/fwrite

    The javascript I am using to initialize and load the xml is:

    PHP Code:
    function loadXMLDoc(dname
    {
    try 
    //Internet Explorer
      
    {
      
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    catch(
    e)
      {
      try 
    //Firefox, Mozilla, Opera, etc.
        
    {
        
    xmlDoc=document.implementation.createDocument("","",null);
        }
      catch(
    e) {alert('Failure to initialize xmlDoc. Error: ' e.message)}
      }
    try 
      {
      
    xmlDoc.async=false;
      
    xmlDoc.load(dname);
      return(
    xmlDoc);
      }
    catch(
    e) {alert('Failure to load xml document. Error: ' e.message)}
    return(
    null);

    When I change nothing except the argument (dname) from the xml to the php, the code returns an empty xmlDoc with no alerts/errors in FireFox. Both xml and php files work in IE.

    Any clue what is wrong here? I am going batty. Even MORE odd to me is that if I copy and paste the php source (from a browser) into an xml file then firefox opens it fine as well. With local files I also have no problems opening a .php extension file as xml. It just won't work for THIS .php file.

    If you are curious what I am using this for, it is for the 'smartsearch' input and select box on the right of the page:
    http://www.thebrasse.com/lotro/index2.php
    That version uses the xml file and should work in FF and IE. When I try to load the seemingly identical output php file I get an empty select box. The box can sometimes take a moment to load. I am wondering if FF is failing because the php file is taking too long to generate itself? Could it be timing out?

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your webserver is advertising the file as Content-Type: text/html
    . To have Firefox interpret it as XML, you would need to serve it as such. Put a header() call before doing any output:
    PHP Code:
    header("Content-Type: text/xml"); 

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't recommend using text/xml, because it's got some odd rules about character encoding. Basically, it says the encoding is US-ASCII unless you state something else in the Content-Type header. In XML, you're meant to specify the encoding in the XML declaration, but that's not possible for text/xml.

    Instead, I'd recommend using application/xml.
    Code PHP:
    header('Content-Type: application/xml');
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Evangelist Alluvian's Avatar
    Join Date
    Jan 2007
    Location
    Orlando, FL
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Makes sense, worked, tastes great, AND less filling.

    Safari still disagrees with me and sends an annoying popup anytime the page is visited (paraphrased, it says item returned by '.load' is not an object), but I am going to look into that.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't see it at first, but seems that you're using synchronous XHR. Don't do that; It doesn't work well on the web, since the browser locks up until the request completes. Possibly, Safari doesn't even allow this? (Just guessing here, but it would make sense).


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
  •