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

The Archive Base Latest Questions

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

I have a function calling another function to get data. That data might be

  • 0

I have a function calling another function to get data. That data might be locally cached, or I may have to go get it. Locally cached is easy. But if I go get it, via $.getJSON, without locking the browser by turning async off, is there some way to still get that data back to the original function?

Ie, in the following code:

1) Since bar() no longer exists when parseData() returns, where is dataX going?

2) Without having yet another callback layer that both bar() and parseData() would call, and without locking the browser while the request is going on, how can I get dataX back from parseData() to foo()?

var foo = function () {

    $('body').text(bar());

};

var bar = function () {

    var parseData = function (dataX) {
        // do something to data
        return dataX;
    };

    if (localStorage.hasOwnProperty('someKey')) {
        return localStorage.getItem('someKey');
    else {
        $.getJSON('http://somewhere.api.com?fubar=good', parseData);
    }

};
  • 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-28T15:09:33+00:00Added an answer on May 28, 2026 at 3:09 pm

    You cannot return when making asynchronous calls. Instead just call foo as a callback:

    var foo = function (text) {
    
        $('body').text(text);
    
    };
    
    var bar = function () {
    
        var parseData = function (dataX) {
            // do something to data
            foo(dataX.someText);
        };
    
        if (localStorage.hasOwnProperty('someKey')) {
            foo(localStorage.getItem('someKey'));
        else {
            $.getJSON('http://somewhere.api.com?fubar=good', parseData);
        }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that is recursively calling itself, and i want to detect
I have the view function in django that written like a dispatcher calling other
I have a logging function that takes the calling object as a parameter. I
Hi I have a function that i want to pass an element to via
I have an AS2 Flash SWF that is calling another AS2 Flash File using
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this
I have a number of iframes calling a function in my main page. Is
So I have a TimerTask task calling a function onTimerComplete() in its run() onTimerComplete()
I have a javascript function for checking errors which I am calling on OnClicentClick
I have got a problem with calling a global function, which takes a pointer

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.