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

  • Home
  • SEARCH
  • 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 4036364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:12:50+00:00 2026-05-20T12:12:50+00:00

I have some code where I wish to call a page method for each

  • 0

I have some code where I wish to call a page method for each row in a datatable.
Each row contains user information and the page method looks for additional data regarding that user, in a certain time period.
If such data exsts, the idea is to then append the data as a new row to the current row.
If no such data exists, move on to the next row.

I begin my code with:

        $.when(GetStartDate(), GetEndDate())
            .then(function () {                    
                GetSchedules();

            })
            .fail(function () {
                failureAlertMsg();
            })

First I retrieve start and end dates via page methods. This works fine. Then I try to call a method for each datarorow in the table:

    function GetSchedules() {
        $('.DataRow').each(function () {
           GetUserSchedule($(this));
        });
    }

This to works no problem. I pass the current data row to a new function which is:

    var currDataRow;
    var currUserID;

    function GetUserSchedule(dr) {
        currDataRow = dr;
        currUserID = currDataRow.find('td').eq(0).text().trim();
        $.ajax({
            type: "POST",
            url: "mypagewithjqueryurl.aspx/GenerateUserSchedule",
            data: "{'StartDate':'" + startDate + "', 'EndDate':'" + endDate + "', 'UserID':'" + currUserID +"'}",    //params
            contentType: "application/json",
            dataType: "json",
            success: function () {
                alert('Succeeded');
            },
            error: AjaxFailed
        });
    }

When I step through the code, the function is called for each row, currDataRow and currUserID is populated as expected,
and the ajax call is performed and here is where the problem lies. The call is made but neither success nor error functions
are called until the calls are completed for all rows. Then the success method is called for each row but the required data has been lost.

How can I restructure my code so that the success function is called for each ajax request?

Thanks in advance for any insight.

  • 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-20T12:12:51+00:00Added an answer on May 20, 2026 at 12:12 pm

    Ajax calls from jquery are asynchronous by default, so it is likely that a handful of calls would all be initiated before any of them succeeds or fails. If you want them to be synchronous, you need to add async: false as a parameter.

    You are also limited to two async requests simultaneously, which is also I’m sure a factor here.

    This doesn’t seem like the best architecture- why not combine all the data into a single request, and set your WebService/PageMethod up so it can handle an array or collection? This is a simpler architecture and will also perform much better than one request per row.

    To pass an array, in C# you’d do something like this in your method:

    using System.Runtime.Serialization;
    ...
    
            [Serializable]
            class Data {
               DateTime StartDate; 
               DateTime EndDate;
            }
    
        // or really any serializable IEnumerable
            public static MyMethod(string data) {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Data[] data = (Data[])serializer.Deserialize(data); 
                foreach (Data item in data) {
                  // do stuff
                }
            }
    

    in Javascript, make your array (or object), e.g.

        var dates = Array();
        // loop
        var datestruct = {
          StartDate: startDate,
          EndDate: endDate 
        }
        dates[index]=dateStruct;
        // end loop
    

    then for data: in your $.ajax:

    $.toJSON(dates)

    You could also build the string manually the way you are now, brackets [] delineate array elements. e.g.

    "{['StartDate':'"+startDate+"','EndDate':'"+endDate+"'],['StartDate ... ]}"

    but why not use something like JSON serializer that does it for you?

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

Sidebar

Related Questions

I have some code that runs a model in a loop. Each iteration of
I have an app with 2 tabbed view, I wish to execute some code
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some code that will change the background color of a specific label
I have some code here that uses bitsets to store many 1 bit values
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code which takes strings representing hexadecimal numbers - hex colors, actually
I have some code that shows results in a table Right now it will

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.