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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:08:40+00:00 2026-05-24T08:08:40+00:00

I am attempting to make consecuitve async ajax calls in order to paint user’s

  • 0

I am attempting to make consecuitve async ajax calls in order to paint user’s schedules into a HTML table via jQuery.
Each response returns a JSON serialized DataSet containing two tables: one of scheduled events and the other contains user info.

The problem I am having is that the user info seems to get mixed up with user events. That is, sometimes the user onfo doesn’t
change for different responses so the scheduled events are tied to an incorrect user. If I set the AJAX async property to false, all is well.

The whole point is to display the schedules one by one as the data is returned instead of making the page freeze until all data is returned.

Is there a way to ensure that the first JAX call completes before the subsequent call executes?

(Perhaps my understanding of setting async to false is incorrrect. Doesn’t it mean that all data is harvested before code execution continues?)

Here is my current approach:

        //  When page loads
    $(document).ready(function () {
        // Get date range            
        debugger;
    //GetStartDate(), GetEndDate() populates date range
    //PopulateParams() does that for remaining parameters
        $.when(GetStartDate(), GetEndDate())
        .then(function () {
            PopulateParams();
            GetUserSchedule();
        })
        .fail(function () {
            failureAlertMsg();

        })
    });

    // Returns schedule for each person listed in between selected start and end dates
    function GetUserSchedule() {
         for (var i = 0; i < arrRequests.length; i++) {
            $.when(
            // Ajax call to web method, passing in string
            $.ajax({
                type: "POST",
                url: URL/default.aspx/GetSchedules",
                data: arrRequests[i],   // example data: {"UserId":"6115","startDate":"\"7/1/2011\"","endDate":"\"7/31/2011\MoreVals: Vals}                    contentType: "application/json",
                dataType: "json",
                success: SuccessFunction,
                error: function (d) { alert('Failed' + d.responseText + '\nPlease refresh page to try again or contact administrator'); }
            })
            )
            .then(function () {

            }
            );
        }
    }

    // On successful completion of call to web method, paint schedules into HTML table for each user
    function SuccessFunction(data) {            
        if (data != null && data.d != null && data.d.Temp != null) {

        // Calls a bunch of functions to paint schedule onto HTML table
        // Data contains two tables: one contains user info and the other contains rows of info for each event for user
        // at times, the user info is not the correct user or the events are not correct for user
    }
  • 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-24T08:08:41+00:00Added an answer on May 24, 2026 at 8:08 am

    Here is how I solved the issue. Hopefully it will help someone else. There may be some typos… this is just meant to show general idea. I called my GetData method recursively:

        //  When page loads
        $(document).ready(function () {
            FunctionToBegin();
        });
    
    
        // Populates params and call method containing AJAX call
        function FunctionToBegin() {
            // Populate any required params here, including the first param required for the first AJAX call
    
            // The following block uses the jQuery.Deferred() object, introduced in jQuery 1.5
            // See http://api.jquery.com/category/deferred-object/
            // the object allows us to chain callbacks, **in the order specified**
    
            // Get date range
            $.when(GetStartDate(), GetEndDate())
                .then(function () {
          var $trCurrent = $('.DataRow:first');
                    //Pass in first userID
                    GetData($trCurrent.find('td:first').text().trim()); 
                })
                    .fail(function () {
                        failureAlertMsg();
                    }
               )
        }
    
    
        function GetData(userID) {
            // get the user id
            UserId = userID;
            // Create a json string containing data needed to retrieve the required data
            jsonTextStringified = null;
            jsonTextStringified = JSON.stringify({ UserId: UserId, startDate: startDate, endDate: endDate, AdditionalValues: AdditionalValues });
            // Ajax call to web method, passing in string
            $.ajax({
                type: "POST",
                url: "/URL/default.aspx/WebMethod",
                data: jsonTextStringified,
                contentType: "application/json",
                dataType: "json",
                async: true,
                success: SuccessFunction,
                error: function (d) { alert('Failed' + d.responseText + '\nPlease refresh page to try again or contact administrator'); }
            });
        }
    
        function SuccessFunction(data) {
          if (data != null && data.d != null && data.d.Temp != null) {
        // Do useful stuff
    
    
        // Process next user id
                nextUserID = SomeMethod();
                if (nextUserID != 0) { GetData(nextUserID) }
            }
            else {
                     nextUserID = SomeMethod();
                     if (nextUserID != 0) {  GetData(nextUserID) }
                }
            }
        }
    

    This general outline permits each async call to complete before processing the next call. In other words, the group of async calls don’t execute all at once and thus, don’t hammer the web method responsible for returning data. In my case, I was returning a dataset containing two tables and the tables returned were inconsistently accurate unless I set the async flag to false (not acceptable for my purpose), or followed the oulined approach.

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

Sidebar

Related Questions

I am attempting to make an HTML Table with data I pull out of
I'm attempting to make ajax calls using jsRoutes in play framework. It works fine
I'm attempting to make a PDF from a HTML document, and this document has
I'm attempting to make a table that has header rows that can be collapsed
I'm attempting to make an XML log file a bit more readable via XSLT.
I am attempting to make an AJAX call to a very small PHP script
I am attempting to make it so a user can say Modify X ,
I am attempting to make a form that takes user inputs for first name
I'm attempting to make a form that asks the user for a number of
Attempting to make a NSObject called 'Person' that will hold the login details for

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.