使用Jquery获取XML并放入html表
我知道之前已经问过这个问题,但是我无法弄清楚是什么问题,我正在尝试使用jQuery加载一个带有显示列表的XML文件,以便可以在一个文件中更新节目,并上传到多个页面。 对我来说,似乎我做的一切都是正确的,但我的知识jquery充其量是脆弱的。 其中大多数只是从其他问题的答案拼凑而成。
我的HTML
我的Jquery
function showData() { $.ajax({ type: "GET", url: "shows.xml", dataType: "xml", success: function getShows(a) { $('#table').append('SHOWS
'); $('#table').append(''); $(a).find('show').each(function(){ var $show = $(this); var date = $show.find('date').text(); var place = $show.find('place').text(); var location = $show.find('location').text(); var time = $show.find('time').text(); var html = '' + date + ' ' + place + ' ' + location + ' ' + time + '
'; $('').append(html); }); } }); }
和XML
9/8 Toads Place New Haven, CT 9PM
这没什么,这看起来对我来说完全正确,所以我非常困惑。 知道我,我错过了半结肠。 > <
谢谢!!
尝试把确切的url…
url: "shows.xml",
… 也许shows.xml与Jquery ajax函数不在同一个文件夹中
你能否确认ajax调用正常并调用success方法。
你可以检查ajax调用和firebug上的响应。
如果xml被正确返回,你可能想尝试下面,稍微修改一下成功方法,例如http://jsfiddle.net/Jayendra/2PFxr/
试试 –
$.ajax({ type: "GET", url: "shows.xml", dataType: "xml", success: function(xml){ $('#table').append('SHOWS
'); $('#table').append(''); $(xml).find('show').each(function(){ var $show = $(this); var date = $show.find('date').text(); var place = $show.find('place').text(); var location = $show.find('location').text(); var time = $show.find('time').text(); var html = '' + date + ' ' + place + ' ' + location + ' ' + time + ' '; $('#show_table').append(html); }); } });