简体   繁体   中英

Adding HTML tags to items pulled through a databse using Javascript?

I'm trying to add 'li' tags to objects I am pulling through a database, right now the results appear as unsorted 'item1 item2 item3 item3' with this code:

var XML = new Array();     
XML = xmlHttpRequest.responseXML;    
alert($(XML).find('ItemName').text());

Any advice would be appreciated, thanks

Imagine each ItemName is an object. Each of those objects can be iterated through using the same methods you are using above

var eachItem = $(XML).find('ItemName');
$.each(eachItem, function(index,value){
  $("#someContainer").append('<li>'+$(value).text()+'</li>');
  //in the above, 'value' is our object', 'index' is the row # at which our object was found.
});

Edit - Edited to reflect needs of OP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM