I am having some ordering issues. I have some code that does the following: on page load, loop through 3 tables and grab content from server and populate table with said content make the table responsive
I am having issues making this work. I can achieve this fine through inspect element (calling functions) but that's not user friendly. I want to know if there's a way I can choose the ordering on what function is being executed. What I have so far is:
$(document).ready(function() {
    if (dateCounter == null){ //start calendar from today's date
        var current = new Date();
        dateChange(current, "", 0); //function one to get grab all contents
        //make table responsive
        var switched = false;
              var updateTables = function() {
                if (($(window).width() < 992) && !switched ){
                    console.log("window width < 992px");
                  switched = true;
                  $("table.responsive").each(function(i, element) {
                      console.log("splitting table up");
                    splitTable($(element));
                  });
                  return true;
                }
                else if (switched && ($(window).width() > 992)) {
                  switched = false;
                  $("table.responsive").each(function(i, element) {
                    unsplitTable($(element));
                  });
                }
              };
        function splitTable(original){...}
        function unsplitTable(original){...}
    }
});
In theory, on page load, it should populate the table first, then make the table responsive, but that's not the case. It seems to be rendering everything concurrently and therefore I get lots of missing/hidden content in my table. I don't know if the AJAX call in my dateChange function has anything to do preventing my table from displaying content correctly.
Following is a code snippet of the dateChange function:
function dateChange(dateInput, nGuests, vName){
    //format dates
    //For each table (3 tables)
    $(".title").each(function(index, element) {
    //prepare HTML for grabbing content from server
        //Grab content from server and pop into table
        $.ajax({
          url: "/grab_Content.asp?boatType="+boatName+"&date="+dateInput+"&guests="+guests+"&boatName="+vName+"",
          dataType:"html",
          success: function(data){
              table.html(data);
          }
        });
    });
}
 
    