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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:22:57+00:00 2026-05-31T05:22:57+00:00

So, I lifted this nice AJAX code from another site. Problem is that I

  • 0

So, I lifted this nice AJAX code from another site. Problem is that I such a lame JavaScript programmer that I can figure out how to get the output onto my page. My startUp() function says o is undefined. I do see the results of the php on the Firebug console.

TIA for your help.

var asyncRequest = function() {
  function handleReadyState(o, callback) {
    if (o && o.readyState == 4 && o.status == 200) {
      if (callback) {
        callback(o);
      }
    }
  }

  var getXHR = function() {
    var http;
    try {
      http = new XMLHttpRequest;
        getXHR = function() {
          return new XMLHttpRequest;
        };
    }
    catch(e) {
      var msxml = [
        'MSXML2.XMLHTTP.3.0', 
        'MSXML2.XMLHTTP', 
        'Microsoft.XMLHTTP'
      ];

      for (var i=0, len = msxml.length; i < len; ++i) {
        try {
          http = new ActiveXObject(msxml[i]);
          getXHR = function() {
            return new ActiveXObject(msxml[i]);
          };

          break;
        }

        catch(e) {}
      }
    }

    return http;

  };

  return function(method, uri, callback, postData) {
    var http = getXHR();
    http.open(method, uri, true);
    handleReadyState(http, callback);
    http.send(postData || null);

    return http;
  };

}();

asyncRequest('GET', 'voterserver.php', function(o) {
    console.log(o.responseText);
});

function startUp() {
    //alert("Here!");
    document.getElementById("user_list").innerHTML=o.responseText;
}
  • 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-31T05:22:57+00:00Added an answer on May 31, 2026 at 5:22 am

    The asyncRequest takes a callback function as the 3rd parameter thats the

    function(o) {
        console.log(o.responseText);
    }
    

    within it

    the value of o passed to that function and is not available in your startUp function.

    you need to rewrite your startup as follows

    function startUp() {
        asyncRequest(
          'GET', 
          'voterserver.php', 
          function(o) 
          {
              document.getElementById("user_list").innerHTML=o.responseText;
          });
    }
    

    I’ve set the indentation to make it clearer.

    You may want too look at using one of the Javascript frameworks that makes this sort of thing alot easier and has good documentation, I use mootools but JQuery is very popular.

    UPDATE

    I tried to make a JSFIddle with thte code you put in your question and it didnt work, I’ve made changes to it to get it to work and its Here for you to try.

    Same thing with MooTools MooTools

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

Sidebar

Related Questions

I found this site/tutorial/demo from another question here on SO. Very nice and clean
I'm writing aspect-ish code more or less lifted from the chosen solution for this
I am looking at this code lifted straight from the MapViewController.m file in the
I'm using this code, and I get the stack trace that is listed below.
I have this simple problem. I'll try to explain with a sample code An
I found myself staring at code that looks similar to this: private double? _foo;
The following code is lifted directly from the source of the Tie::File module. What
I overloaded the 6 signals listed on this site http://www.cplusplus.com/reference/clibrary/csignal/signal.html Then i ran my
In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and
Simplified from this question and got rid of possible affect from LinqPad(no offsensive), 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.