0

I'm trying to figure out how to pull data from an XML file that isn't hosted on my own site. I'm completely new to this so I have no idea where I'm going wrong. I can pull that data from my own site easy. Any help would be appreciated, thanks!

<script type="text/javascript">
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  url = "http://elcu.herobo.com/testarea/include/cd_catalog.xml"
  xmlhttp.open("GET",url,false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML;

  document.write("<table border='0' cellpadding='1' cellspacing='1' width'90%' id='1' class='tablesorter'><thead><tr> <th>Artist</th> <th>Title</th> <th>Country</th></thead><tbody>");

  var x=xmlDoc.getElementsByTagName("CD");
  for (i=0;i<x.length;i++)
  {
      document.write("<tr><td>");
      document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("COUNTRY")[0].childNodes[0].nodeValue);
      document.write("</td></tr>");
  }
  document.write("</tbody></table>");

0

3 Answers 3

0

For security reasons you are, by default, not allowed to do cross-domain requests to get XML data (same-origin policy). If you want to get data across domains, you usually need to use JSON-P as your format, or setup a proxy within your own domain that you can access the data through.

0

I thought I'd never write this, but, "You might consider using jQuery for this." It provides all the sauce for the different browsers and also support for JSON-P that you'll need for CORS, unless you can get the server to start returning CORS headers to permit your access.

0

If you have access to page, that isn't hosted on your server (I suppose you don't), you can use JSONP (for more details, see this answer), otherwise you should use PROXY (see this answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.