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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:34:25+00:00 2026-05-26T14:34:25+00:00

I have web methods that are called via AJAX in a .Net 4.0 web

  • 0

I have web methods that are called via AJAX in a .Net 4.0 web app. In many cases, the AJAX calls are made repeatedly in a for loop. My problem is, the information the web method is syncing to my server is time stamped and therefore must be synced in the order in which I am sending it to AJAX. Unfortunately, it seems whatever finishes first, simply finishes first and the time stamps are all out of order. I need to basically queue up my AJAX requests so that they execute in order rather than Asynchronously, which I know is the A in AJAX so this might be a totally dumb question.

How do I force the order of execution for AJAX calls done in a for loop?

Edit: Some code

                    for (var i = 0; i < itemCnt - 1; i++) {

                    try {
                        key = items[i];
                        item = localStorage.getItem(key);
                        vals = item.split(",");
                        type = getType(key);


                        if (type == "Status") {
                            var Call = key.substring(7, 17);
                            var OldStat = vals[0];
                            var NewStat = vals[1];
                            var Date1 = vals[2];
                            var Time1 = vals[3];
                            var miles = vals[4];

                            try {
                                stat(Call, OldStat, NewStat, Date1, Time1, miles, key);

                            }
                            catch (e) {
                                alert("Status " + e);
                                return;
                            }

                        }
                        else if (type == "Notes") {
                            var Call = key.substring(6, 16);
                            var Notes = item;
                            try {
                                addNotes(Call, Notes);
                            }
                            catch (e) {
                                alert("Notes " + e);
                                return;
                            }
                        }
                        else if (key == "StartNCTime" || key == "EndNCTime") {
                            var TechID = vals[0];
                            var Date = vals[1];
                            var Time = vals[2];
                            var Activity = vals[3];
                            var Location = vals[4];
                            var Type = vals[5];

                            try {
                                logTime(TechID, Date, Time, Activity, Location, Type, 
                            }
                            catch (e) {
                                alert(key + ' ' + e);
                                return;
                            }

                        }
                    }
                    catch (e) {
                        alert(key + ' ' + e);
                        return;
                    }
                }

function stat(Call, OldStat, NewStat, Date1, Time1, miles, key) {
$.ajax({
    type: "POST",
    dataType: "json",
    contentType: "application/json",
    url: "Service.asmx/update_Stat",
    data: '{ CallNumber:"' + Call + '", OldStat:"' + OldStat + '", NewStat:"' + NewStat + '", Date1:"' + Date1 + '", Time1:"' + Time1 + '", Miles: "' + miles + '"}',
    success: function (data) { },
    error: function (xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        alert("Sync Update Stat: " + err.Message);
        location = location;
    }
});
}

function logTime(TechID, Date, Time, Activity, Location, Type, key) {
$.ajax({
    type: "POST",
    dataType: "json",
    contentType: "application/json",
    url: "Service.asmx/nonCallTime",
    data: '{ TechID:"' + TechID + '", Date1:"' + Date + '", Time1:"' + Time + '", Activity:"' + Activity + '", Location:"' + Location + '", Type: "' + Type + '"}',
    success: function (data) { },
    error: function (xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        alert("Sync Non Call Time: " + err.Message);
        location = location;
    }
});
}

function addNotes(Call, Notes) {
$.ajax({
    type: "POST",
    dataType: "json",
    contentType: "application/json",
    url: "Service.asmx/addNote",
    data: '{ Call:"' + Call + '", Notes:"' + Notes + '"}',
    success: function (data) { },
    error: function (xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        alert("Sync Notes: " + err.Message);
        location = location;
    }
});

}

  • 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-26T14:34:26+00:00Added an answer on May 26, 2026 at 2:34 pm

    You have to use callbacks.

    function ajax1(){
       //..some code
       //on ajax success:
       ajax2();
    }
    
    //etcetera...
    

    Or might I suggest using a javascript library like jQuery to synchronize your ajax requests for you.

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

Sidebar

Related Questions

I have a web Method in my C# that is called via Jquery ajax
Some existing web services I consume have methods that look something like this: List<Employee>
I have a web application that will need to access code behind methods as
I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I'm using javascript and jQuery. I have a problem that my web app has
I have an ASP.NET MVC web app which has a really basic subscription system
I have a ASP.NET Web Forms page that does a good amount of processing
I have a Web Service with Just one Web Method that returns a boolean
I have a web service (ASMX) and in it, a web method that does

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.