Reputation: 14219
I have the following jQuery
$.ajax({
type: "GET",
url: "http://f.cl.ly/items/0i1V1L1k2F440L1m2Y0G/pointdata.xml",
dataType: "xml",
success: parseXml
});
function parseXml(xml) {
$(xml).find('point').each(function() {
var lat = $(this).children('lat').text();
var long = $(this).children('long').text();
alert(lat + long);
});
}
Trying to read data from this XML file
You can also see a live jsFiddle here
For some reason, the variables lat and long aren't being assigned for each element. What am I doing wrong? Any help would be much appreciated. Thanks in advance.
Upvotes: 0
Views: 130
Reputation: 150253
Your parseXML
function works
You're probably violating the same origin policy.
You can't send ajax
requests to other domains.
Note that lat + long
concats strings so '1' + '2'
is '12'
not 3.
If you want the result to be 3, parse to int first.
Upvotes: 3