I have the following javascript:
function getMessageFromXML(xml) {
alert('xml: ' + xml);
alert("Text of message: " + $(xml).find('dataModelResponse').find('adminMessage').text());
return $(xml).find('dataModelResponse').find('adminMessage').text();
}
which is being executed on the following XML:
<dataModelResponse>
<adminMessage>BARF</adminMessage>
<adminData>
<identifier>123456</identifier>
</adminData>
</dataModelResponse>
I know that the XML is correctly passed in, because of the first alert, but the message is showing up as blank for some reason. I verified that there were exactly 1 message and 1 dataModelResponse elements in the xml, using the .length modifier for similar find() queries, but for some reason, I can’t get it to print out the correct message.
Suggestions?
EDIT: Changed the tag name I was searching for. Posted in between two revisions, sorry.
Replace
$(xml).find('dataModelResponse').find('message').text();with$(xml).find('message').text();.The documentation for
jQuery.find()states:The root level element of your XML block is
dataModelResponse. By calling$(xml).find('dataModelResponse'), you are essentially asking for adataModelResponsewithin yourdataModelResponse.