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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:50:08+00:00 2026-06-11T21:50:08+00:00

I have a function where I’m making a call to a MVC controller that

  • 0

I have a function where I’m making a call to a MVC controller that returns a JSON blob, with the contents of some back-end action. This JSON blob is being used to populate a table that is presented to the end-user.

My function currently looks something like this:

function getJsonFromController(path) {
    var blob = null;

    $.getJSON(path, function (data) {
        blob = data;
        console.log('inside getjson : ' + blob);
    });

    console.log('outside getjson : ' + blob);
    return blob;
}

…And a calling action that looks like this:

$('#action-button').click(new function () {
    blob = getJsonFromController('A/B?pageId=1');

    console.log('in click event: ' + blob);
    $.tmpl($template, blob).appendTo($('#table-body'));
});

When I run the webpage/action that calls this, I get the following results, in the given order:

outside getjson: null
in click event: null
inside getjson: [object Object] 

I’ve attempted some other configurations (.complete of .getJSON(), directly returning a value from $.getJSON()) to attempt to echo the ‘data’ from the callback out to the enclosing scope’s blob variable, but so far, the blob only appears to have value within the getJSON callback.

That being said, I’m also aware that JavaScript is a lexically scoped language, so it could be a matter of all the anonymous function chains being executed.

The question: I can see that my blob is appearing correctly inside $.getJSON. Now, how do I get my blob out?

  • 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-11T21:50:09+00:00Added an answer on June 11, 2026 at 9:50 pm

    AJAX requests are asynchronous. You may do it synchronous (note that it will freeze your web page until request is done), but suppose better will be to do something like below:

    function getJsonFromController(path) {
        var blob = null;
    
        $.getJSON(path, function (data) {
            blob = data;
            console.log('inside getjson : ' + blob);
            $.tmpl($template, blob).appendTo($('#table-body'));
        });
    }
    

    And click:

    $('#action-button').click(new function () {
        blob = getJsonFromController('A/B?pageId=1');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function getCartItems in cart.js and I want to call that function in
Inside my Controller i have function that runs after user clicks on item, which
I have function that have been colled in stored procedure. The function returns a
I have function getMemory() which returns VARIANT (mfc). It is said that in ulVal
I have function that has : ob_start(); //Include of some files $content = ob_get_contents();
I have function that returns the index of a character GetCharFromPos(Pt: TPoint): Integer; now
I have function Start() that is fired on ready. When I click on .ExampleClick
I have this code in my controller (admin): function save(){ $model = $this->getModel('mymodel'); if
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
i have function that changes background color of element and src of image. in

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.