I am reading a xml file and saving the data in array.But I am not able to use the array values later.I have declared everything as global. When I put an alert(myData[3]); I am getting "undefined".Please help.

Below is my code:

function modify_data(xml)
{
//alert("tyur");
$(xml).find('person').each(function(){
    phone = $(this).find('phone').text();
        email = $(this).find('email').text();
    name = $(this).find('name').text();
    myArray_name[n]= name;
    myData[n]=myArray_name[n];
       alert(myData[n]);
    n=n+1;
           });
alert(data);
alert(myData[3]);

}

Recommended Answers

All 3 Replies

Did you remember to initialize n to zero somewhere? Did you remember to use dataType: "xml" in your jQuery ajax options?

Did you remember to initialize n to zero somewhere? Did you remember to use dataType: "xml" in your jQuery ajax options?

Thanks,
I forgot to initialize n to zero,now it is working.

Glad to help.

PS: Be sure to mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.