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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:21:03+00:00 2026-05-30T14:21:03+00:00

I have a problem with the onreadystatechange when i make ajax request, it used

  • 0

I have a problem with the onreadystatechange when i make ajax request, it used to call the function but
now it does not call the processRequest.

I am not sure if I edited something or what..Can sombody help..

function createAjaxObject(url, callback) 
{
    /// @par Implementation 
    var req = init();
  req.onreadystatechange = processRequest;

    /// @brief  Creates a ajax object based on the runnunf browser    
    function init() 
    {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject) 
            return new ActiveXObject("Microsoft.XMLHTTP");
    }

    /// @brief Checks if request is complete and HTTP call is successful
    function processRequest () 
    {   

        /// readyState of 4 signifies request is complete

        if (req.readyState == 4){

            /// status of 200 signifies sucessful HTTP call
            if (req.status == 200){
                if (callback) 
                callback(req.responseXML);
            }
        }
    }

     this.doPost = function(param) {

             if (req.readyState == 4) {

        /// make a HTTP GET request to the URL asynchronously
        req.open("POST",url, true);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        req.setRequestHeader("Content-length",param.length);
        req.setRequestHeader("Connection", "close");
        req.send(param);

        }
    }
}

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-30T14:21:05+00:00Added an answer on May 30, 2026 at 2:21 pm

    This line:

    if (req.readyState == 4) {
    

    …(and the corresponding }) shouldn’t be in the function you’re assigning to this.doPost. E.g.:

    this.doPost = function(param) {
    
        /// make a HTTP GET request to the URL asynchronously
        req.open("POST",url, true);
        req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        req.setRequestHeader("Content-length",param.length);
        req.setRequestHeader("Connection", "close");
        req.send(param);
    };
    

    I’m assuming the way you use that is:

    var obj = new createAjaxObject(url, callback);
    obj.doPost();
    

    …because the code quoted never actually calls the function that does the post, but rather just assigns it to a property on this. The usual place you assign properties to this is within a constructor function, hence my using new above.

    (BTW: The overwhelming convention in JavaScript code is to use initial caps on functions that are used as constructors, e.g. CreateAjaxObject [or better yet, just AjaxObject] rather than createAjaxObject.)

    There are a bunch of other changes I’d make to that code, but I think that’s the minimum.


    Side note: I’d recommend using a JavaScript library like jQuery, Prototype, YUI, Closure, or any of several others. They smooth over a lot of browser differences and provide a huge amount of well-tested utility functionality, letting you focus on what you actually need to do.

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

Sidebar

Related Questions

I have a problem with an AJAX call that i make to login a
I have a race condition in which I do not want an AJAX call
I have problem with fancybox. I want to write a function that will run
Today I have a bit of a problem. I have an ajax script that
I have the following code which works great:- $('.ajax a').click(function() { getpageajax(this.href); return false;
I have a problem in giving Ajax functionality to a hyperlink. I have files
I do have a communication problem here between my Java servlet and an Ajax
I have a problem using AJAX. The 2 functions that are called via the
I have an AJAX post function I am using for my communication between my
This javascript code run without problem in chrome and IE but have a problem

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.