I’m pretty new to jquery xml parsing and have hit a wall.
I have an XML source data file like this called tracker2.xml (very simple):
<spotter num="17555" report_at="2013-01-29 04:05:17" lat="45.0463562" lng="-93.4922943"></spotter>
I am trying to pull “lat”, “lng”, and “report_at” as variables to use later in the code. I have this so far and to me seems to be the proper code. I added the alert(report_at) to troubleshoot. When run, the alert displays “[object]”.
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "tracker2.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml)
{
$(xml).find('spotter').each(function()
{
var report_at = $(this).attr('report_at');
var lats = $(this).attr('lat');
var lngs = $(this).attr('lng');
});
}
alert(report_at);
I’m sure i am missing something stupid. Anyone that can help me will be my hero. Thanks!!
you are alert the
report_atvariable out of your for loop, try it inside your loop