Reputation: 7805
I want to create a list from a php xml file, so I read some tutorials and put together this:
$.blockUI();
$.get('venuesxml.php', function (data) {
$('#MenuList').append("<p><label><strong>Id</strong></label>
<label><strong>venue type</strong></label></p>");
$(data).find('marker').each(function () {
$('#MenuList').append("<p><label>" +
$(this).find('ID').text() + "</label><label>" +
$(this).find('venue_type').text() + "</label></p>");
});
});
$.unblockUI();
However I noticed that this will only work if the xml looks like this:
<markers>
<marker>
<ID>1</ID>
<venue_type>2</Name>
</marker>
</markers>
However it looks like this:
<markers>
<marker id="67" venue_type="2"/>
</markers>
How would I get the data in this case? Thanks
Upvotes: 0
Views: 191
Reputation: 144739
You can use attr
method:
$(data).find('marker').each(function () {
var p = "<p>" +
"<label>" + $(this).attr('id') + "</label>" +
"<label>" + $(this).attr('venue_type') + "</label>" +
"</p>";
$('#MenuList').append(p)
});
Upvotes: 1
Reputation: 74738
try changing with this and see if this works for you:
$(this).text($(this).attr('id')) + "</label><label>" +
$(this).text($(this).attr('venue_type')) + "</label></p>");
Upvotes: 1
Reputation: 2219
You want to retrieve the XML attributes instead of nodes within <marker>
Try replacing $(this).find('ID').text()
with $(this).attr('id')
and $(this).find('venue_type').text()
with $(this).attr('venue_type')
Upvotes: 1