Chrome / Safari not working...javascript problem?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • npm
    New Member
    • Apr 2007
    • 57

    Chrome / Safari not working...javascript problem?

    Hi
    I've checked out this page (and it works fine) in FF, IE, Opera, Chrome and Safari:

    http://www.w3schools.c om/dom/tryit.asp?filen ame=try_dom_lis t_loop

    But when I try and tweak it for a site I'm working on, it doesn't work in Chrome and Safari.

    I used their exact external javascript to load the xml file:

    Code:
    function loadXMLDoc(dname) 
    {
    var xmlDoc;
    if (window.XMLHttpRequest)
      {
      xmlDoc=new window.XMLHttpRequest();
      xmlDoc.open("GET",dname,false);
      xmlDoc.send("");
      return xmlDoc.responseXML;
      }
    // IE 5 and IE 6
    else if (ActiveXObject("Microsoft.XMLDOM"))
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.async=false;
      xmlDoc.load(dname);
      return xmlDoc;
      }
    alert("Error loading document");
    return null;
    }
    And I use the same basic set up in javascript to display my results in the html page:

    Code:
    <script type="text/javascript">
    xmlDoc=loadXMLDoc("xml/stations.xml");
    
    x=xmlDoc.getElementsByTagName('city');
    for (i=0;i<x.length;i++)
    {
    document.write(x[i].childNodes[0].nodeValue);
    document.write("<br />");
    }
    </script>
    Here's a shorter version of the xml file I'm using:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <stations>
    	<station>
    		<city>City 1</city>
    		<freq>105.7 FM</freq>
    	</station>
    	<station>
    		<city>City 2</city>
    		<freq>90.3 FM</freq>
    	</station>
    </stations>
    So...it works in my 5 browsers when I use theirs on w3schools.com, but when I upload it all to our server, it won't work in Chrome and Safari.

    I don't understand, any help would great. Thanks in advance!
  • icesign
    New Member
    • Aug 2009
    • 5

    #2
    I think the problem is with the path you're requesting. Try to use path relative to the root (something like this '/mysite/otherdir/xml/stations.xml').

    PS: Why don't you use the jQuery?

    Comment

    Working...