How to parse this XML ajax response?

Hamberger

New Member
I am trying to parse some data with jQuery retrieving by ajax from a Java servlet or action. This is my worst week, everything goes bananas. Here it is my XML response: \[code\]<ajax-response> <response> <item> <name>ok</name> <value>true</value> </item> <item> <name>menuDiv</name> <value> Some HTML Menu</value> </item> </response></ajax-response>\[/code\]And I am trying to get just the "menuDiv" value that is "Some HTML" :\[code\]$.ajax({ type: "GET", url: basePath+'mostrarMenu.do', dataType: "xml", success: parseXml});function parseXml (xml) { var menu = $(xml).find("item"); menu.each(function(i, value) { alert(value[0]); if (value =http://stackoverflow.com/questions/10603475/='menuDiv') { alert("Esto es el menudiv:"+value); } if (( value != null ) || ( value != '') || ( value != ' ')) { $('#menuDiv').append(value); } else alert ("anda el else"); });\[/code\]\[code\]alert(value[0]);\[/code\] and \[code\]if ( value =http://stackoverflow.com/questions/10603475/='menuDiv') {\[/code\] returns nothing, and the last \[code\]if\[/code\] makes the menu visible, but with the others items too, like a \[code\]true\[/code\] word appearing before a handsome menu. Any help or recommendation would be very appreciated. Thanks. EDIT 2:With this function, now I am getting plain text (not rendered html) and all "< items >":\[code\]function parseXml (xml) { var menu = $(xml).find("item"); menu.each(function(i, value){ if(( value != null ) || ( value != '') || ( value != ' ')){ $('#menuDiv').append($(value)); } else alert ("anda el else"); }); } }\[/code\]I have change dataType: 'html' and my menu is visible, but I keep on trying to select just one ITEM on my XML and not all of them...
 
Back
Top