如何从XML Feed中获取数据?看下面的示例:
$(document).ready(function () {
$.get('http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=thunderbay', function (d) {
$('body').append('<dl />');
$(d).find('route').each(function () {
var $route = $(this);
var tag = $route.find("tag").text();;
var title = $route.find("title").text();;
var html = '<dt> </dt>';
html += '< p> ' + tag + ' - ' + title '< /p>';
html += '</dd>';
$('dl').append($(html));
console.log(d);
});
}); });
谢谢! :)
答案 0 :(得分:0)
$(document).ready(function () {
$.get('http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=thunderbay', function (xml) {
$('route', xml).each(function (index, route) {
var tag = $(route).attr('tag');
var title = $(route).attr('title');
$('#dl').append(
$(document.createElement('dt'))
.append(
$(document.createElement('p'))
.text(tag + ' - ' + title)
)
);
});
});
});
更新了小提琴here