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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:19:31+00:00 2026-05-20T10:19:31+00:00

I have an AJAX post function I am using for my communication between my

  • 0

I have an AJAX post function I am using for my communication between my server & the users webpage. But I have a problem with dealing with the response from the server in my resuable function.

If you see the following example you will see that the function outputEmailDetailsResult() is called & run on the line “post( “forgotPass.py”, emailParam, outputEmailDetailsResult() );”, ie, when the function is passed as a param. But it should only run inside the post function in reation to the server response:

var xmlhttp;
    function post( dest, params, callbackFunction )
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            callbackFunction;
        }
    }

    xmlhttp.open("POST",dest,true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send( params );  // "fname=Henry&lname=Ford");
}


    function emailLoginDetails()
{
    var emailParam = "email=sam"; // + document.getElementById( "forgotEmail" ).innerText;
    alert( emailParam );
    post( "forgotPass.py", emailParam, outputEmailDetailsResult() );
}

function outputEmailDetailsResult()
{
    try
    {
        document.getElementById( "statusOutput" ).value = xmlhttp.responseText;
    }
    catch ( ex )
    {
        document.getElementById( "statusOutput" ).value = "Failed to get response from server";
    }
}

I am new to passing functions as a parameters(I think they’re called callbacks?) & I am unsure I am doing it correctly?

  • 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-20T10:19:32+00:00Added an answer on May 20, 2026 at 10:19 am

    Move the parentheses from the callback parameter to the function. Like this.

    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      callbackFunction();
    }
    
    ...
    
    post( "forgotPass.py", emailParam, outputEmailDetailsResult);
    

    What you did was calling outputEmailDetailsResult() before post, so you were actually passing the result of the outputEmailDetailsResult() function as the parameter rather than the function itself as the parameter.

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

Sidebar

Related Questions

I have a form that uses jQuery to submit an ajax post and it
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I am using asp.net MVC to develop an application that will have ajax interactions.
I have $.ajax({ url: identity, success: function(data) { ProcessIdentityServer(data) } }); When 'data' is
I've started the following skeleton for an ajax/post/update function I'm wanting to write in
I have this jQuery ajax navigation tabs plugin that I created using some help
I have this recursion loop where inside the function I have atleast 2 ajax
I have this AJAX code, but it doesn't seem to throw the 'alert' method.
I have a jquery Ajax call function that I use to submit form 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.