Reputation: 7969
I am getting data from xml file when I download xml file on local server it is working fine, but when I am giving online path of xml file it is not working. I read about something about that I think it is a crossdomain issue, but how to call crossdomain file in html .
<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");
}
xmlhttp.open("GET","http://www.mydomain.com./myfile/xml_9646.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
</script>
Upvotes: 1
Views: 234
Reputation: 119867
If you have control over the back end of your domain, you could have something like PHP to read the remote XML for you. Your server will act like a bridge/proxy for your JS code and the remote XML. Since JS can't talk over other domains, you ask your server (which is in your domain) to read it for you.
Upvotes: 0
Reputation: 178350
If the server implement CORS you can
https://stackoverflow.com/a/10083975/295783
$(document).ready(function() {
jQuery.support.cors = true; // IMPERATIVE for IE(8) support
$.ajax({
type: "GET",
url: "http://itunes.apple.com/au/rss/topfreeapplications/limit=10/xml?partnerId=1002&partnerUrl=http%3A%2F%2Fwww.s2d6.com%2Fx%2F%3Fx%3Dc%26z%3Ds%26v%3D3868801%26t%3D",
dataType: "xml",
success: function(xml) {
$(xml).find('...').each(function(){
var id = $(this).find("...").text();
// ....
});
}
});
});
Upvotes: 1