Please can someone advise me why the following code appears to work fine in Internet Explorer, but not in Chrome or Firefox; I’ve tried all variations I can think of using .get, .ajax, .load but none seem to want to work. The XML file is one of w3c’s examples, and I’m using jquery-latest.min.js:
$(document).ready(function() {
$.get("http://www.w3schools.com/xml/simple.xml", function(data){
$(data).find("food").each(function(){
alert($(this).find("name").text());
});
});
});
Thank you for looking over my question!
It’s about Same Origin Policy: IE allows ajax queries on a different host website but other browsers don’t.
To by-pass this you can use JSONP or perform the query on a local php file which will read the distant site with
file_get_contentsif you haveallow_url_fopentrue.