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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:57:21+00:00 2026-06-08T07:57:21+00:00

I am having a problem, or perhaps a lack of understanding, with the jQuery

  • 0

I am having a problem, or perhaps a lack of understanding, with the jQuery execution order of $.get() function. I want to retrieve some information from a database server to use in the $.ready() function. As you all know, when the get returns, it passes the data to a return handler that does something with the data. In my case I want to assign some values to variables declared inside the ready handler function. But the problem is, the return handler of $.get() does not execute until after ready has exited. I was wondering if (a) am I doing this right/is there a better way or if (b) there was a way around this (that is, force the get return handler to execute immediately or some other fix I’m not aware of). I have a feeling this is some closure thing that I’m not getting about JavaScript.

As per request, I’ll post an example of what I mean:

$(function() {
    var userID;

    $.get(uri, function(returnData) {
                   var parsedData = JSON.parse(returnData);
                   userID = parsedData.userID;
               });
  });

So as you can see, I’m declaring a variable in ready. Then using a get call to the database to retrieve the data needed. Then I parse the JSON that is returned and assign the userID to the variable declared before. I’ve tested it with a couple alerts. An alert after the get shows userID as undefined but then an alert in get’s return handler shows it to be assigned.

  • 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-08T07:57:24+00:00Added an answer on June 8, 2026 at 7:57 am

    $.get() is asynchronous. You have to use a callback to fill your variable and do the computation after the request is complete. Something like:

    $(document).ready(function(){
    
        $.get( "yourUrl", function( data, textStatus, jqXHR ) {
            var myData = data; // data contains the response content
            // perform your processing here...
            registerHandlers( myData ); // you can only pass "data" off course...
        });
    
    });
    
    // your function to register the handlers as you said you need to.
    function registerHandlers( data ) {
        // registering handlers...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jQuery plugin jEditable. Problem I'm having is that I want whatever is editable
I am having problem to get a numerical value for this expression where I
hello I am having problem related to https:// . I have used FB.getLoginStatus(function(response) function
I'm having a problem with a TinyMCE plugin using long GET parameters. On my
I'm using jQuery Typewatch but it's no longer maintained and I'm having a problem
I'm having an odd problem with asp.net MVC razor view. I want my model
I am having a problem inserting and removing objects to/from the database using Linq
I am writing a program in Qt c++ and I'm having some problem handling
I'm having a problem resolving a hostname using python's (2.6.2) socket class. From the
Hello I am having a problem with Django trying to get it deployed on

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.