我試圖用jQuery顯示XML文件中的數據,儘管我擁有正在重複的正確數據量的數據。 JS:用jQuery顯示HTML格式的數據
$(function(){var xml = '<?xml version="1.0" ?><sports file_date="2014-02-08T08:30:11.207"> <sport id="1" name="Football"><event id="3" name="Eng. Premier League"><match id="670358" live_id="91583" name="Liverpool - Arsenal" start_date="2014-02-08T12:45:00" streaming="0"><bets><bet code="Ftb_Mr3" id="10178143" name="Match Result"><choice id="75726090" name="%1%" odd="2.10"/><choice id="75726093" name="Draw" odd="3.40"/><choice id="75726096" name="%2%" odd="3.30"/></bet></bets></match></event></sport></sports>';
var xmlDoc = $.parseXML(xml);
var $xml = $(xmlDoc);
var $match = $xml.find("match");
var $odds = $match.find("choice");
var game = $match.attr('name'),
odd = $odds.attr('odd');
$("#title").append(game);
$odds.each(function(){
$("#odds").append('<li>' +odd+ '</li>');
});
});
你可以在這裏看到:
任何建議將是非常有幫助我也想這個數據(將一個外部XML文件),每隔30秒進行檢查使用ajax。
謝謝,我知道這將是服用點明顯有任何建議讓Ajax工作? – wroughtec
@wroughtec,http://stackoverflow.com/questions/11421373/read-xml-with-jquery-javascript-every-5-seconds。這應該有幫助... – sinisake