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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:44:38+00:00 2026-05-30T01:44:38+00:00

–Updated Code to make it…more simple– Kind of a strange situation, according to w3schools

  • 0

–Updated Code to make it…more simple–

Kind of a strange situation, according to w3schools my code should work, but for some reason it doesn’t…connect. Here’s my code for my java script.

XHTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
    </head>
    <body>
        <p id="intro">Hello</p>
        <script type="text/javascript" id="announce" src="announce.js"></script>
    </body>
</html>

JavaScript

/*jscript*/
var newannouncement = document.createElement('p');
newannouncement.id = 'announcing';
newannouncement.appendChild(document.createTextNode('Here is an announcement'));
var scr = document.getElementById('announce');
scr.parentNode.insertBefore(newannouncement, scr);      

if(window.XMLHttpRequest)
{
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

**xmlhttp.open("GET", "catalog.xml",false);**
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var x=xmlDoc.getElementsByTagName("cd");
for (i=0; i<x.length; i++)
{
    alert("for")
}

XML

<?xml version="1.0"?>
<catalog 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="catalog.xsd">
    <cd>
    <author>Ferdi</author>
    <date>1192</date>
    </cd>
    <cd>
    <author>JRR</author>
    <date>1995</date>
     </cd>
</catalog>

Update 1

Due to the fact that I considered the previous code, too confusing, I’ve changed it to make it simpler so that I can actually find out what the heck is cracking off. The problem appears to be the xmlhttp.open() as the for loop doesn’t run. I’ve switched to xhtml as it keeps the code…easier to read (for me) and I understand that document.write() doesn’t work.

The problem

I simply just call the function in-line. The *‘s indicate the line that fails. Now, I’ve tried just leaving it as announce.xml (leaving the announce.xml in same directory) and I’ve now tried moving it down a directory. I’ve also tried adding /../ but to no avail.

I didn’t see any ‘technical’ requirements on the w3schools website…so I’m assuming like html it works out of the box.

Further notes

If possible if you’re going to suggest technology, such as AJAX, could you please describe what it is, what it does and if possible a link to a suitable place to find out more. 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-05-30T01:44:39+00:00Added an answer on May 30, 2026 at 1:44 am

    (This isn’t really an answer, but a comment, however I have several points I’d like to make which is easier in an answer).

    Are you using a debugger with your browser (FireBug extention for Firefox, or the one built into Chrome or IE)? Is the Console in the debugger reporting an error? Also debuggers let you track the requests the browser makes. Does it show your request?

    There are several points independent from your problem:

    • Be very careful with w3schools. Despite its name it’s unrelated to W3C and the quality is often very lacking.
    • Any special reason you aren’t using an AJAX framework such as jQuery? (It’s great not using one, if you what to understand how AJAX works in it’s basics, but a framework really simplifies everything).
    • You are doing a synchronous request, which you never should do. Synchronous requests block the browser making it unresponsive for the user.
    • You need to be very careful with document.write. It only works during page loading and because you are doing a synchronous request. In other cases you can easily “overwrite” your page with it.

    EDIT:

    The problem is most likely what @bazmegakapa suggested: XMLHttpRequest usually only works when on a web server. What you need to do is install a web server locally on your development computer and use it for testing. This is usually quite simple. Even Apache is quickly installed and runs with little configuration. Or a package with Apache and including a DB server (MySQL) and PHP called “AMP” which are often specifically made for local web page development and testing and are setup even easier. And finally many web development IDEs have a simple web server built in (I like Aptana Studio, for example).

    What you are doing is commonly called “AJAX” which stands for “Asynchronous JavaScript and XML”, except you are not doing it asynchronously, which you should not. Have a look at a short tutorial from the Mozilla Developer Network work how to do it right: https://developer.mozilla.org/en/AJAX/Getting_Started

    If you still have problems, then you’ll need to give more detailed information, most importantly the error message the browser gives in its console (see my remark on debuggers above).

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

Sidebar

Related Questions

With the following code, I can receive 1 request and write it: function listen()
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I need to clean up various Word 'smart' characters in user input, including but
I'm wondering why the below code I'm trying to use to pull in a
So to start, I have an array of XML files. These files need to
Welcome to Spring Roo. For assistance press CTRL+SPACE or type hint then hit ENTER.
When I view JSON data as an alert when the page loads, I see:
An extension to my previous question: Text cleaning and replacement: delete \n from a

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.