Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:13:07+00:00 2026-06-18T05:13:07+00:00

I am trying to read a XML using ajax request in jquery. Below is

  • 0

I am trying to read a XML using ajax request in jquery. Below is the code,it’s working fine in IE but when I run this on Chrome i am facing this error

Uncaught TypeError: Cannot call method ‘hasChildNodes’ of undefined

$.ajax({

    type: "GET",
    url: "tree1.xml",
    dataType:"xml",
    success: function(xml){
        root=xml.documentElement;
        childs=root.childNodes;
        for(var i=0;i<childs.length;i++){
            z=childs[i].childNodes;
            adChilds(z,childs,oNode);


            function adChilds(a,b,c){
                if(a[i].hasChildNodes()){
                    adNode(b[i].nodeName,c);
                    var oNode_ch=oNode1;
                    for(var j=0;j<a.length;j++){
                        child1=a[j].childNodes;
                        adNode(child1[0].nodeValue,oNode_ch);
                    }
                }
                else{adNode(a[0].nodeValue,oNode);}
            }
        }

error is pointing at this line.

if(a[i].hasChildNodes()){

Can anyone suggest me where am I going wrong.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:13:09+00:00Added an answer on June 18, 2026 at 5:13 am

    You’re doing this:

    z=childs[i].childNodes;
    

    then, in the first line of adChilds(z,childs,oNode);, you’re doing this:

    if(a[i].hasChildNodes()){
    

    But, i isn’t an index into the children of a. It’s an index into the parent’s of a’s children. Thus, if the parent of a doesn’t have the same number of children as a has children, you will go out of index.

    I don’t know exactly what you’re trying to accomplish in adChilds() so I’m not sure what fix to suggest, but I presume you that if you want to deal with the children of a, you should get the number of children of a and make sure you only access the number that actually exist


    Some coding suggestions:

    1. I’d strongly suggest you use real variable names. Names like a, b, c and z for intermediate variables are cryptic and make your code hard to read.

    2. All local variables should be preceded with var at first definition (or defined at the top of the function), otherwise they become global variables which is asking for trouble, especially with asynchronous callback functions.

    3. When you see errors that aren’t obvious to you upon first inspection of your code, then set a breakpoint in your favorite debugger and step through the code and examine the state of the variables to see exactly why you’re getting the error. If you don’t know how to use a debugger, learn. They are built into most browsers, easy and absolutely essential to efficient debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read the below xml using XMLDocument, but I am not
So I'm using jQuery's AJAX function to read some XML for me and it's
Trying to read this xml using Linq to XML <Root> <shelves> <bookNumber>12</bookNumber> <coverType unit=H>soft</coverType>
I'm trying to read xml files from assembly, this is my code: private Assembly
What I am not trying to do: Simply read XML in IE using jQuery.
I m trying read XML data using XML parser from Url( https://....etc ). But
I am trying to read the xml file email.xml (Data below) using the python
I am trying to read the XML Documentation file (C#) using this ocde -
I am trying to read this XML file using PHP and I have two
I am trying to read a value from an XML file using LINQ. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.