如何将xml文件内容加载到div.
这是我需要加载XML内容的HTML
XML数据
http://123.png http://11.png http://11.jpg Memory Card MSMT2G $6.99http://www.test.com/Sony http://i2.jpg Apple iPad $579.95http://www.test.com/Apple
而xml文件名是 something.xml
我尝试了几种方法,但它没有用:(
我尝试了下面的方法,但没有奏效.
$('something.xml').find('name').each(function() { $("#news-container").append($(this).text() + "
"); });
palaѕн.. 19
试试这个:
// Load the xml file using ajax $.ajax({ type: "GET", url: "something.xml", dataType: "xml", success: function (xml) { // Parse the xml file and get data var xmlDoc = $.parseXML(xml), $xml = $(xmlDoc); $xml.find('category[name="My t"] logo').each(function () { $("#news-container").append($(this).text() + "
"); }); } });
参考:1 jQuery.ajax() 2. parseXML()
试试这个:
// Load the xml file using ajax $.ajax({ type: "GET", url: "something.xml", dataType: "xml", success: function (xml) { // Parse the xml file and get data var xmlDoc = $.parseXML(xml), $xml = $(xmlDoc); $xml.find('category[name="My t"] logo').each(function () { $("#news-container").append($(this).text() + "
"); }); } });
参考:1 jQuery.ajax() 2. parseXML()