jQuery appends [object HTMLInputElement]

tradnangphuc

New Member
I have this AJAX function for retrieving XML with the usernames from the Java servlet. I parse the usernames here and send them to the \[code\]addToUserList\[/code\] function, where I append with jQuery. But \[code\][Object HTMLInputElement]\[/code\] is the only thing which appends to the list. When I run the AJAX function on my browser console the returned XML has a first element which is \[code\][object HTMLInputElement]\[/code\], but there are usernames following it.\[code\]function displayFriendList(){ $.ajax({ url : '/getFriendList?userid=' +userid, type : "POST", dataType: 'xml', success : function(data) { $(data).find("friend").each(function () { addToUserList($(this).find("username").text()); }); }, })}\[/code\]Here is the addToUserList function\[code\]var userList = new Array();function addToUserList(friend){ var exists = false; for(var i=1; i<userList.length; i++){ if(userList==friend){ exists = true; break; } } if(!exists){ userList.push(friend); $('#userList').append("<a>"+friend+"</a></br>");\[/code\]and a part of the returned xml\[code\]<data><friend><username>[object HTMLInputElement]</username></friend><friend><username>asa</username></friend><friend><username>asda</username></friend><friend><username>cece</username></friend>\[/code\]
 
Back
Top