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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:32:12+00:00 2026-05-30T15:32:12+00:00

The title of this question is not very clear but I cannot explain what

  • 0

The title of this question is not very clear but I cannot explain what I am asking without providing some code.

I am making a page which submits reports (which are arrays) using AJAX. I have functions stored in a library which submit the array to the PHP page that look like this:

function saveReport(params)
{
    var url="reports/save.php";

        xmlHttp=GetXmlHttpObject();
        if (xmlHttp==null)
        {
            return false;
        }
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("POST",url,true);
        //Send the proper header information along with the request
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(params);

}

function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
        if (xmlHttp.responseText == 'complete')
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
}

(I don’t believe the GetXmlHttpObject() function is relevant to the question)

I would like to be able to call the saveReport() from my page like this

success = saveReport(params);
if (success == true)
{
    alert('success');
}
else
{
    alert('failure');
}

So the function saveReport() needs to return a value which is returned from the function stateChanged() when it is called so that the page that called saveReport() can then decide what to do – which may be a different on different pages. Is there any way of doing this?

I realise that it may be impossible the way I am trying but is there something I can do to the same effect.

  • 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-30T15:32:13+00:00Added an answer on May 30, 2026 at 3:32 pm

    Is there a reason why you’re rolling your own Ajax helper?

    In this situation you’re going to need a callback function to be fired when the server has responded so that you can do something with the response, whether it be a success or fail.

    Obviously, you can use something like jQuery.ajax but that might be overkill for something this simple.

    You could try one of the many micro Ajax libraries at http://microjs.com/#ajax to achieve what you’re after.

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

Sidebar

Related Questions

The question title is not very clear so let me explain. I am trying
I know the title of this question is not very descriptive, but I didn't
Please suggest or change some suitlable title for this question as i am not
This question has been asked here before, but the author wasn't very clear and
Maybe the title of the question is not very self-explanatory but I don't know
I'm not sure if this question fits properly, but I'm wondering in tile-based games,
i didn't really know how to title this question, but here's a thing that
I have no good title for this question, but my problem is to set
The title of this question is a bit misleading, but I couldn't summarize this
Sorry for the not very descriptive question title. I'm not very sure how to

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.