jQuery not reading or counting nodes of XML file correctly -
jQuery not reading or counting nodes of XML file correctly -
this question has reply here:
how homecoming response asynchronous call? 11 answersi have xml document:
<?xml version='1.0' ?> <root> <row> <title>homeward bound</title> </row> <row> <title>escape witch mountain</title> </row> .... .... </root>
my jquery read xml is:
$(document).ready(function () { var data; $.ajax({ type: "get", url: "titles.xml", datatype: "xml", success: function (e) { info = e; }, error: function () { alert("the xml file not processed correctly."); } }); alert($(data).find("root row").length);
... .. .
the alert shows 0 - despite there beingness several records.
is there wrong way i'm reading xml file - or ".find" wrong?
thanks help, mark
scope of success argument remains in method only. set value variable variable , utilize variable outside. or write code in success function:
$(document).ready(function () { $.ajax({ type: "get", url: "titles.xml", datatype: "xml", success: function (e) { alert($(data).find("root row").length); }, error: function() { alert("the xml file not processed correctly."); }}); });
jquery xml xml-parsing
Comments
Post a Comment