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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:17:21+00:00 2026-05-31T08:17:21+00:00

I have many instances of the same type of problem using jQuery. Probably because

  • 0

I have many instances of the same type of problem using jQuery. Probably because I am missing some basic knowledge (jQuery newb). In my $.Ajax calls to get data – on the success: I perform many calls to other functions based on the data that gets returned. The calls need to be made in a specific order but this does not seem to happen. If I have a call to another jQuery function that I wrote and then three line later have a call to yet another function (which depends on some events that happen in the first function call) the second call is happening first. Ran this with debugger set many times in two different $.Ajax calls and it happens this way. Am I doing something completely wrong?

BTW – the data is coming in just fine and populating my table and form items. Per request I am posting code below – the comments show that GetInventory needs to execute before BuidlNav

       $(document).ready(function () {
       $('#searchNow').css('visibility', 'hidden'); //Hide Search Now button
       $("#popup").css("display", "none");
       $('#submit').prop('disabled', true);
       $.ajax({
           type: "POST",
           url: "mypage.aspx/mywebmethod",
           contentType: "application/json; charset=utf-8",
           data: "{}",
           dataType: "json",
           success: function (states) {
               var jsonCodes = JSON.parse(states.d);
               for (var i in jsonCodes) {
                   $("#Select0").append(new Option(jsonCodes[i].regionname, jsonCodes[i].region_id));
               }
               var first = getUrlVars()["region"];
               if (first) {
                   debugger;
                   $.fn.SetAllSelectors(reg);
                   $.fn.GetInventory(1, 10, reg, 'rank', 'asc'); //This should happen first
                   $.fn.BuildNav(); // This depends on GetInventory having been executed already.                     
               }
               else {
                   var myText = 'United States';
                   $("#Select0 option").filter(function () {
                       return $(this).text() == myText;
                   }).first().prop("selected", true);
                   $.fn.GetChildRegions("Select0");
               }
           }
       });          
   }
);
  • 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-31T08:17:23+00:00Added an answer on May 31, 2026 at 8:17 am

    If GetInventory and BuildNav also use ajax, you’ll need a structure more like this. When making ajax calls, the data is fetched while not holding up the next command line, so chances are your 2nd or 3rd function is being called before the first finishes.

    $.ajax({    
       type: "POST",
       url: "mypage.aspx/mywebmethod",
       contentType: "application/json; charset=utf-8",
       data: "{}",
       dataType: "json",
       success: function (states) {
            getInventoryAndBuildNav(states);
       },   
       ... 
    });
    
    function getInventoryAndBuildNav(states){
        $.ajax({    
            ....
            url: "mypage.aspx/getinventory",
            success: function (inventory) {
    
                $.fn.BuildNav();
            },   
            ... 
        });
    }
    

    The best way to accomplish this is to build functions for each item and allow a callback method to be passed.

    Think of it this way

    $.ajax({    
       type: "POST",
       url: "mypage.aspx/mywebmethod",
       contentType: "application/json; charset=utf-8",
       data: "{}",
       dataType: "json",
       success: function (states) {
           //This will trigger second since we had to wait for the process to finish
            alert('The Ajax call has been made, finished, and the data received');
       }
    });
    
    //This will trigger FIRST since the ajax call was initiated, but we're still waiting
    alert('The Ajax call has been made. We're moving on to the next call.');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have similar instances of the same web application running across many domains. I
I have many variable-sized lists containing instances of the same class with attribute foo,
I have a class named dot and many instances of this same class are
I have a class that I can have many instances of. Inside it creates
I have only one class with many instances. Every instance is observer of couple
We have an ASP.NET web application hosted by a web farm of many instances
I have come across a weird problem concerning composite keys and one-to-many relationship. I
I have two C# classes that have many of the same properties (by name
I have many years of experience in Java including Swing, Servlet and JDBC, but
I have many items inside a list control. I want each item to have

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.