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 3280270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:41:08+00:00 2026-05-17T19:41:08+00:00

I don’t know if it works or not, but I am concluding this because

  • 0

I don’t know if it “works” or not, but I am concluding this because the code posted here, works (except for what’s in the for loop (stupid DOM), but that’s not the focus) ONLY after two clicks. I’m assuming this is because it is not getting the XML document till it’s created, which is at the end of the first click.

However, if I were to put XMLhttpRequest.open and XMLHttpRequest.send methods BEFORE the onreadystatechange function, the code will not execute inside the nested if statement (the one that checks readystate/status). I have tested this with alert or document.write.

Any ideas what is going wrong?

if (window.XMLHttpRequest)
{
    var xmlhttp = new XMLHttpRequest();
}

function lessonList()
{   
    var xmldoc = xmlhttp.responseXML;

    xmlhttp.onreadystatechange = function() 
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            var getTitle = xmldoc.getElementsByTagName('title');
            var lessonList = document.getElementById('lesson-list');

            for (i = 0; i < getTitle.length; i++)
            {
                var lessonTitle = document.createElement('li');
                lessonTitle.nodeValue = getTitle[i].childNodes[0].nodeValue;

                lessonList.appendChild(lessonTitle);
            }
        }
    };

    xmlhttp.open("GET", 'file.xml', true);
    xmlhttp.send(null);
}
  • 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-05-17T19:41:08+00:00Added an answer on May 17, 2026 at 7:41 pm

    +1 idealmachine’s answer. To clarify, there isn’t one single Document instance associated with a single XMLHttpRequest, where loading XML from the response just updates the contents of the document. It’s not like calling Document.load().

    Instead, when the request is sent, the XMLHttpRequest object drops the old Document that was referred to by its responseXML, and when the response is received it creates a new Document instance with the response. If you kept a reference to the old value of responseXML that’s still a valid Document, but it’s the old XML document from the previous response, not the new one.

    Additionally remember your var i in the for-loop to avoid an accidental global. And setting the nodeValue is meaningless on an Element node; you would need to document.createTextNode(string) and append it instead.

    You’ll usually use a helper function to get/set the text content of an Element since traditional-DOM makes it such a pain. DOM Level 3 Core’s element.textContent property is the easy way, but it doesn’t exist in IE or some older browsers.

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

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
I don't know if this question is trivial or not. But after a couple
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know whether this is really possible, but I'm trying my best. If
(Don't know if this is strictly on-topic, but I don't see any better Stack
I don't know: if this works. if it's a good idea. what it is
Don't know a better title but here is what im trying to do. I
Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a
I don't know why this double json response are not successful: [{first_content:content,...}][{second_content:content,...}] So i

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.