By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

Chrome / Safari not working...javascript problem?

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

http://www.w3schools.com/dom/tryit.asp?filename=try_dom_list_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:

Expand|Select|Wrap|Line Numbers
  1. function loadXMLDoc(dname) 
  2. {
  3. var xmlDoc;
  4. if (window.XMLHttpRequest)
  5.   {
  6.   xmlDoc=new window.XMLHttpRequest();
  7.   xmlDoc.open("GET",dname,false);
  8.   xmlDoc.send("");
  9.   return xmlDoc.responseXML;
  10.   }
  11. // IE 5 and IE 6
  12. else if (ActiveXObject("Microsoft.XMLDOM"))
  13.   {
  14.   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  15.   xmlDoc.async=false;
  16.   xmlDoc.load(dname);
  17.   return xmlDoc;
  18.   }
  19. alert("Error loading document");
  20. return null;
  21. }
And I use the same basic set up in javascript to display my results in the html page:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. xmlDoc=loadXMLDoc("xml/stations.xml");
  3.  
  4. x=xmlDoc.getElementsByTagName('city');
  5. for (i=0;i<x.length;i++)
  6. {
  7. document.write(x[i].childNodes[0].nodeValue);
  8. document.write("<br />");
  9. }
  10. </script>
Here's a shorter version of the xml file I'm using:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <stations>
  4.     <station>
  5.         <city>City 1</city>
  6.         <freq>105.7 FM</freq>
  7.     </station>
  8.     <station>
  9.         <city>City 2</city>
  10.         <freq>90.3 FM</freq>
  11.     </station>
  12. </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!
Aug 4 '09 #1
Share this Question
Share on Google+
1 Reply


P: 5
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?
Aug 5 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.