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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:02:03+00:00 2026-06-02T06:02:03+00:00

I have some ajax code in an html doc that changes the text of

  • 0

I have some ajax code in an html doc that changes the text of a button to text stored in another html doc in the same domain. The text is in the body tag of the second html document.Like this:

<body> Text</body>

So the code makes an ajax request, parses the response to create an xmldoc. When I try to use the

getElementByTagName("body") or even getElementByTagName("html") 

I get an emepty HTMLcollection. But when I use the

queryselector("body") I can get to the text. The log to console prints undefined. 

Here’s the full code:

function gettxt()
 {
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.open("GET", "http://localhost/ajax2.html", true);  
xmlhttp.onreadystatechange = function() 
{
  if (xmlhttp.readyState === 4) {  
    if (xmlhttp.status === 200) 
    { 
      allText = xmlhttp.responseText;   
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(allText, "application/xml");            
    var bodyobj=xmlDoc.getElementsByTagName("body");
    console.log(bodyobj.lemgth);                        
      document.getElementById("secbtn").value=bodyobj;        
    }
  }
}

xmlhttp.send(null);

}

What am I missing? Thanks.

  • 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-02T06:02:04+00:00Added an answer on June 2, 2026 at 6:02 am

    I know what I was doing wrong. I was setting the button’s text to bodyobj instead of bodyobj[0].innerHTML.

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

Sidebar

Related Questions

I have some jquery code that is doing an ajax lookup and returning comma
I have some jQuery code. I have called an Ajax function file, file.php, that
I have some problems with this code? Here is my code that creates text
I have a script that attaches actions to some objects in my HTML code.
I have written some jQuery ajax code where I am sending a request to
I have java script code to set some of the properties of ajax controls.
I have some AJAX work that brings across an additional form element that I
I have some forms that communicate with server using AJAX for real reasons: cascade
I wrote some ajax code that sends values to a php file for validation
I have a jquery AJAX function which retrieves some HTML markup and displays it

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.