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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:45:09+00:00 2026-05-21T19:45:09+00:00

I am making an ajax call inline as below and storing the response in

  • 0

I am making an ajax call inline as below and storing the response in global variable and accessing later for some performance reasons.

<script type="text/javascript"> 
   var gblAjaxResponse;
   $.ajax({
      url: '/test.aspx',
      success: function(data) {
       gblAjaxResponse=data;
      }      
    });                                     
</script>

Now i want to use this global variable in document.ready of an ajax file. Once the DOM is ready , i have to use this data on some divs on that page.

$(document).ready(function() {

 alert(gblAjaxResponse);   

});

I have the following questions now.

1) As ajax is asyncrnous call is it sure that i always get the response into that global variable by the time i ready document.ready.
2) Are there any chances that my document.ready code gets executed below the ajax success handler returns
3) I don’t want to use asyn false option as it can hang.
4) Is there anyway to check if success is completed and returned data.

any suggestions will be appreciated

  • 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-21T19:45:10+00:00Added an answer on May 21, 2026 at 7:45 pm

    1) As ajax is asyncrnous call is it
    sure that i always get the response
    into that global variable by the time
    i ready document.ready.

    No, document.ready can be executed before.

    2) Are there any chances that my
    document.ready code gets executed
    below the ajax success handler returns

    Yes

    4) Is there anyway to check if success
    is completed and returned data.

    Basing on kennis’ answer, you could do this:

    <script type="text/javascript">
       var gblAjaxResponse;
       $.ajax({
           url: '/test.aspx',
           success: function(data) {
              gblAjaxResponse = data;
              myCallbackFunction();
          }
       });
    
       function myCallbackFunction(){
           alert(gblAjaxResponse);
       }                              
    </script>
    

    If you need to use gblAjaxResponse in document.ready, you could do this too:

    <script type="text/javascript">
       var gblAjaxResponse = null;
       $.ajax({
           url: '/test.aspx',
           success: function(data) {
              gblAjaxResponse = data;
          }
       });
       $(document).ready(function(){
           //Wait until gblAjaxResponse has value:
           var intervalId = setInterval(function(){
               if(gblAjaxResponse !== null){
                   clearInterval(intervalId);
                   myCallbackFunction();
               }
           }, 100);
       });
       function myCallbackFunction(){           
           alert(gblAjaxResponse);
       }                              
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an AJAX call to retrieve some plain text: $.ajax({ url: programData.txt, type:
I'm working on a web page where I'm making an AJAX call that returns
I am making a request to a CGI program using AJAX. The response sends
When making an AJAX call from the client, the server responds with Hebrew text.
When making an ajax call, when contentType is set to application/json instead of the
I am making an AJAX call (with jQuery) to retrieve a PartialView . Along
I am making ajax call(ASP.NET 3.5) from dropdown change handler and trying to pass
I am making an ajax call using the following code. $.ajax( { url: '/BuildingCompany/EditAjax/'
Problem I am making ajax call to server1 i.e. csce and once I got
am making an ajax call to retrive json data i then store the retrived

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.