我知道這已被問過,但我無法弄清楚什麼是錯的,我試圖加載一個XML文件與使用jQuery的節目列表,以便節目可以在一個文件中更新,並上傳到多個頁面。對我來說,似乎我做的一切都是正確的,但我的知識jquery充其量是脆弱的。大部分內容都是從其他問題的答案拼湊而成。使用jquery獲取XML並將其放入html表
我的HTML
<aside id="shows"class="aside shadow">
<div class="text" id="table">
<div class="more low"> MORE SHOWS </div>
<div class="less"> LESS SHOWS </div>
</div>
</aside>
我的Jquery
function showData() {
$.ajax({
type: "GET",
url: "shows.xml",
dataType: "xml",
success: function getShows(a) {
$('#table').append('<h2>SHOWS</h2>');
$('#table').append('<table>');
$(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 = '<tr><td class="bold">' + date + '</td><td class="hide">' + place + '</td><td>' + location + '</td><td class="bold">' + time + '</td></tr></table>';
$('<table>').append(html);
});
}
});
}
和XML
<shows>
<show>
<date>9/8</date>
<place>Toads Place</place>
<location>New Haven, CT</location>
<time>9PM</time>
</show>
</shows>
這什麼也不做 這完全看我的權利,所以我超級困惑。瞭解我,我錯過了一個半結腸。 > <
謝謝!!
是否包含jQuery的? – mowwwalker
我確實包括jQuery – Jay
什麼意思,什麼都沒有發生?打開你的控制檯,看看它是否有任何說明。 ctrl + shift + j與鉻,ctrl + f4與Firefox,alt + f4與Ie – mowwwalker