MinnRick
asked on
Parsing XML With jQuery
Hello Experts -
I have the following block of jQuery in a web form:
-- Rick
I have the following block of jQuery in a web form:
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "xml.aspx",
dataType: "xml",
success: parseXML
});
function parseXML(xml) {
var strOutput;
$(xml).find('root3').each(function () {
strOutput = strOutput + $(this).text() + ' - ';
alert(strOutput);
});
}
});
</script>
For purposes of this question assume that the target XML is properly formed and contains three elements called <root3>, each containing the text 'fubar'. I would expect the alert within the parseXML function to fire three times, the first displaying 'fubar -', the second displaying 'fubar - fubar -' and the third displaying 'fubar - fubar - fubar -'. The first firing instead displays 'undefinedFubar -'. Can someone please tell me why, and what I have to do to get rid of that initial undefined reference? Thanks much.-- Rick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER