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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:27:46+00:00 2026-06-13T19:27:46+00:00

I am writing a simple AJAX code as a way to learn the basics

  • 0

I am writing a simple AJAX code as a way to learn the basics and introduce myself to the concepts. The following code grabs the contents of a textfile located on the server and passes to a variable, popping into an alert box.

My problem is that the code runs perfectly in the Eclipse IDE ‘Open with Web Browser’ but nowhere else.

var http = createRequestObject();
var responseContent;

function createRequestObject() {
   var objAjax;
   var browser = navigator.appName;
   if(browser == "Microsoft Internet Explorer"){
       objAjax = new ActiveXObject("Microsoft.XMLHTTP");
   }else{
       objAjax = new XMLHttpRequest();
   }
   return objAjax;
 }

function getContent(name){
   http.open('get', name);
   http.onreadystatechange = function() {
       if (http.readyState == 4) {
          responseContent = http.responseText;
       }
   };
   http.send(null);
 }   

 $(document).ready(function() {
   getContent('newcontent.txt');
   alert(responseContent);
 });

Does anyone know why this might be? Is there a problem with the code? If so, why would it work fine in eclipse but not elsewhere?

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-13T19:27:47+00:00Added an answer on June 13, 2026 at 7:27 pm

    Summarizing into a short answer:

    The XHR is sent in the getContent function and a listener is attached.

    Then, getContent returns and the execution alerts the undefined variable responseContent.

    At some point the XHR is answered, the readyState changes to 4 and listener is called.

    It is only then that the responseContent variable is assigned.

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

Sidebar

Related Questions

I'm looking into writing simple graphics code in Android and I've noticed some synchronized()
I'm writing a simple class in C++ for a class (school, not code). I
I'm writing a simple AJAX call that returns a full HTML page and then
Here's the situation: I'm writing a simple AJAX application that performs CRUD functions. When
I'm writing an application and I'm trying to tie simple AJAX functionality in. It
Could somebody recommend to me the proper way of writing filter functions for ajax
I am writing the code for getting the accordion contents when I click on
I am writing a simple Django application and wish to add ajax paging using
I am writing simple parallel program in C++ using OpenMP. I am working on
I'm writing simple program to communicate between smart devices and I receive 11001 when

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.