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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:04:02+00:00 2026-06-06T15:04:02+00:00

Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,

  • 0

Possible Duplicate:
return AJAX callback return

I have made a JQuery code using AJAX, but despite all my efforts (trying $.post, $.get and $.ajax) I am not able to get any response nor using it in my code.
Example code:

var r = $.post("ajaxpage.php", function(data) {return data});
console.log(r); // nothing
  • 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-06T15:04:03+00:00Added an answer on June 6, 2026 at 3:04 pm

    One of the most common misconceptions of beginner programmers about Javascript and AJAX is to treat the AJAX request as a “normal” function, doing variable assignments or expecting to use immediately the AJAX response in their code.

    That’s not how it works though; let’s try to understand how a correct implementation works.

    AJAX stands for Asynchronous JavaScript and XML.

    We will ignore for a while the XML part (which is more about how the request is carried on, via XMLHttpObject), the Javascript bit is quite obvious (it’s the scripting language we use, with or without JQuery), let’s focus on asynchronous.

    Think about AJAX this way: it is roughly like sending a work email to a colleague, while you’re at work, and giving some info; and requesting an action to be taken and/or other info in return; no matter if your friend answers immediately or not, you still have to continue your job because the answer could be delayed (your friend may be particularly busy today).
    When your friends answers with relevant info, only then you will address the matter and take appropriate actions. If an action is requested, your colleague will carry it on only when he receives your email.

    AJAX works in a similar way: from client-side, you make a request to a server-side page, and expect an action (like writing a row in a database) or a response (some data fetched server-side from the page you are calling.

    The important bit is that your JavaScript code continues its execution regardless of the completion of the round-trip, as there can be a significant delay when your client (remember that JS runs client-side) makes an AJAX call to the server (slow server, slow connection, and so on).

    So you can’t expect to do things like:

    var r = $.post("ajaxpage.php", function(data) {return data});
    

    because $.post doesn’t actually “return” a value like a “regular” function, the variable r cannot be valued by $.post

    Instead, you should organize your code based on the done event, which is fired after the AJAX call has completed: it guarantees (if there have been no failures, like server-side errors, not found pages, etc.) that we actually have a response to use in your code on success.
    With that event we can call a function that receives the response as a parameter and actually uses it.

    $.post("ajaxpage.php").done(useMyResponse);
    // rest of the code
    
    function useMyResponse(response)
    {
        // do fancy things with the response like:
        console.log(response); // works!
        // or maybe
        $("#someElement").html(response);
    }
    

    A shorthand for this would be:

    $.post("ajaxpage.php",function (response) { 
         // use response
         console.log(response);
    });
    

    Edit: i’m not a native English speaker, forgive my mistakes.

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

Sidebar

Related Questions

Possible Duplicate: jQuery: Return data after ajax call success I have the following function
Possible Duplicate: Kill Ajax requests using JavaScript using jQuery Here is the simple code
Possible Duplicate: c++ virtual function return type I have a simple but confusing question
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
Possible Duplicate: Why does Enumerable.All return true for an empty sequence? Code: var line
Possible Duplicate: jQuery: Return data after ajax call success I wrote a script which
Possible Duplicate: jQuery AJAX submit form I have a form on a page A,
Possible Duplicate: Why does getDay return incorrect values? (javascript) I have the following code
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: How to make return key on iphone make keyboard disappear? I have

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.