In my jQuery ajax method, the “data” it returns as following format:
<root>
<result sender='BlackSmith' nickName='Blac'></result>
<result sender='AristleJohnson' nickName='AJ'></result>
.
.
.
</root>
In my jQuery function, my code is:
$(data).find('result').each(function(){
alert("test");//it never shows up, I don't know why?
var userId=$(this).attr('sender');
var nickName=$(this).attr('nickName');
});
However, the alert never shows up, which means $(data).find(‘result’) does not work here. Could you help me? Thank you.
I don’t think you can pass HTML/XML into jQuery as you are with $(data). Typically, the DOM in question is already on the page somewhere, and you do $(“result”) instead.
In your case, you should dataType to “xml” in the ajax request itself, and then jQuery will actually parse the results and give them to you in your success() handler.