Parsing XML With jQuery

Hello Experts -
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 () {
            type: "GET",
            url: "xml.aspx",
            dataType: "xml",
            success: parseXML
        function parseXML(xml) {
            var strOutput;
            $(xml).find('root3').each(function () {
                strOutput = strOutput + $(this).text() + ' - ';

Open in new window

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
Who is Participating?
first loop :
from line 11, strOutput is undefined, to prevent replace line 11 by : var strOutput = "";
MinnRickAuthor Commented:
Yep, thanks.  That one was a  *duh*  on my part - the variable IS undefined until you give it a value.  Much appreciated.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.