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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:45:27+00:00 2026-06-02T06:45:27+00:00

I need to return the data from an nested ajax call but also need

  • 0

I need to return the data from an nested ajax call but also need the ajax call to stay asynchronous.

I found some related questions but can’t get it to work in the situation below. I assume returnData is being returned before the ajax call is done, but I can’t find an solution.

function makeRequest(command, postData){

    var returnData;

    $.ajax({

        url: 'call.php?command='+command,
        data: postData,
        type: 'POST'

    }).done(function(data){
        returnData = data;
    });

    return returnData;
}
  • 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-02T06:45:29+00:00Added an answer on June 2, 2026 at 6:45 am

    Yes since this call is async returnData is returned immediately. If you need to use returndata pass it to a function in the callback

    function makeRequest(command, postData, functionToCallAfterAjax){
    
        var returnData;
    
        $.ajax({
    
            url: 'call.php?command='+command,
            data: postData,
            type: 'POST'
    
        }).done(function(data){
            functionToCallAfterAjax(data);
        });
    
    
    }
    

    Of course you could pass the function to call as a parameter.

    This means that if your code was meant to do:

    var returnedData = makeRequest(command, postData);
    anotherFunction(returnedData);
    

    you should do simply (using the code above)

    makeRequest(command, postData, anotherFunction);
    

    and everything will work

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

Sidebar

Related Questions

I need to return some json data from controller. Anyone know how to do
Basically I need to return some data from a SQL Server table in the
I need to create WebMethod that will get some data from db and return
I need to return measurement data from a database. Unfortunatly the data is in
I need to get data from JSON, transferred by Ajax from the client. Basically
A simple ajax call, the php echos some xml text I need to appear
I need advice on using stored procedures with Entity Framwork 4.x to return data
I need to write a data structure that can return a different Price for
I need to create a web service that returns XML data to some of
I need to return a list of counties, but I need to filter out

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.