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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:14:08+00:00 2026-06-18T04:14:08+00:00

All, I have a fairly simple javascript script that changes some text in my

  • 0

All,

I have a fairly simple javascript script that changes some text in my html page. The weird thing is that the data is only changed if I have an alert. If I hide the alert as a comment, the data doesn’t appear on the webpage. To be specific, here are the relevant pieces of the JS code:

var index=0;
var xmlObject=null;

function calcIndex(){
  return index++;
}

function showNextName(){
  retrieveNextName();
  var someText = xmlObject.getElementsByTagName("name")[0].childNodes[0].nodeValue;
  document.getElementById('nextName').innerHTML=someText;
}

function retrieveNextName(){
  var index=calcIndex();
  request = createRequest();
  if (request == null) {
    alert("Unable to create request");
    return;
  }
  var url= "Ajax_retrieveName.php?index=" + index;
  request.open("GET", url, true);
  request.onreadystatechange = createXml;
  request.send(null);
  alert("abc");
  //If the alert above is missing, the html is not modified...
}

function createXml() {
  if (request.readyState == 4) {
    if (request.status == 200) {
      xmlObject = request.responseXML;
    }else{
      return;
    }
  }else{
    return;
  }
}

Does anyone know what might be causing that?

  • 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-18T04:14:09+00:00Added an answer on June 18, 2026 at 4:14 am

    The problem is that XML object is not immediately available, because the request isn’t finished yet, so the callback hasn’t been called yet. (Alerting allows the request to finish in the time before you clock the alert box away.)

    A better solution would be to have an updateElementHtml(newHtml) function and call that from within the callback.

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

Sidebar

Related Questions

I have a fairly simple bash script that does some grep to find all
I have a fairly simple dynamic html structure of a table that contains links
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
Hi I have been working on a fairly simple page with very light and
I have a fairly simple android app, it gets protobuf data from a web
I have a fairly simple asp grid view, tied to an object data source.
I have a fairly simple user control that represents a basic login control. So
I have a fairly simple web application that gets a list of items from
Fairly simple question that I can't remember. We have three environments: Local machine (unique
i have a very simple rails application that is ajax-based for some of it's

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.