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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:00:41+00:00 2026-06-12T07:00:41+00:00

When the page loads, this function is run, but only gets to alert 2,

  • 0

When the page loads, this function is run, but only gets to alert 2, I suspect it doesn’t reach alert 3 due to a bug in the previous line var id_array = xmlDoc.getElementsByTagName("id");. I have tried researching getElementsByTagName() to see if I am using it correctly and I still feel like I am.

var xmlhttp;
xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200){

        var xmlDoc = xmlhttp.responseXML;
    alert("2");
        var id_array = xmlDoc.getElementsByTagName("id");
    alert("3");
    for(id in id_array)
    {
        // do something with the id 
    }
    }
}
xmlhttp.open("POST", "xmlDoc.xml", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(); 
alert("1");

this is a sample of the xml document it should read from. The actual file generates x amount of “id”s with varying information from an sql database.

<id>
    <name><![CDATA[<?php echo $query_array["name"]; ?>]]></name>
    <latitude><![CDATA[<?php echo $query_array["latitude"]; ?>]]></latitude>
    <longitude><![CDATA[<?php echo $query_array["longitude"]; ?>]]></longitude>
    <color><![CDATA[<?php echo $color_array["color_id"]; ?>]]></color>
    <color_r><![CDATA[<?php echo $color_array["red"]; ?>]]></color_r>
    <color_g><![CDATA[<?php echo $color_array["green"]; ?>]]></color_g>
    <color_b><![CDATA[<?php echo $color_array["blue"]; ?>]]></color_b>
    <text><![CDATA[<?php echo $user_array["comment"]; ?>]]></text>
</id>
<id>
    <name><![CDATA[<?php echo $query_array["name"]; ?>]]></name>
    <latitude><![CDATA[<?php echo $query_array["latitude"]; ?>]]></latitude>
    <longitude><![CDATA[<?php echo $query_array["longitude"]; ?>]]></longitude>
    <color><![CDATA[<?php echo $color_array["color_id"]; ?>]]></color>
    <color_r><![CDATA[<?php echo $color_array["red"]; ?>]]></color_r>
    <color_g><![CDATA[<?php echo $color_array["green"]; ?>]]></color_g>
    <color_b><![CDATA[<?php echo $color_array["blue"]; ?>]]></color_b>
    <text><![CDATA[<?php echo $user_array["comment"]; ?>]]></text>
</id>
<id>
    <name><![CDATA[<?php echo $query_array["name"]; ?>]]></name>
    <latitude><![CDATA[<?php echo $query_array["latitude"]; ?>]]></latitude>
    <longitude><![CDATA[<?php echo $query_array["longitude"]; ?>]]></longitude>
    <color><![CDATA[<?php echo $color_array["color_id"]; ?>]]></color>
    <color_r><![CDATA[<?php echo $color_array["red"]; ?>]]></color_r>
    <color_g><![CDATA[<?php echo $color_array["green"]; ?>]]></color_g>
    <color_b><![CDATA[<?php echo $color_array["blue"]; ?>]]></color_b>
    <text><![CDATA[<?php echo $user_array["comment"]; ?>]]></text>
</id>

So my EXPECTED behavior would be that id_array (in this example) gets 3 cells (one per occurence) and each of those cells contains all the data within the tags.

But again, I suspect a bug in the assignment of id_array is keeping anything from happening.

Any help would be great!

  • 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-12T07:00:42+00:00Added an answer on June 12, 2026 at 7:00 am

    set

    xmlhttp.setRequestHeader('Content-Type',  'text/xml');
    

    and see if

    xmlhttp.responseXML
    

    does not yield null resulting in an error when trying to do .getElementsByTagName("id").

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

Sidebar

Related Questions

Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I've seen this done before, but I'm not sure how. When my page loads,
I am trying to run some JQuery script on a particular page but only
I have a page that loads content through AJAX. Among this content are some
Take a look at this page: http://pearl.tinderfields.com/ In IE6 the menu's background image loads
I'm unable to get this jquery statement to work on page load but it
When I try to run this page (video.php), I get the following error: Parse
I have several JavaScript functions that need to run when the page loads to
On page load I'm bootstrapping my data to my collections via this technique .
I have my web applicatoin initialize method run based upon the page that is

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.