Using ajax in a callback where the parent process itself relies on an ajax call
  
 
     
     
             
                 
 
 
         up vote 
         5 
         down vote 
 
         favorite 
         
 
 
 
 
 
             
 
             
 
     
 
 I'm working with an application that uses DataTables to generate a HTML table which is populated by data from an ajax request.   This is fairly simple:   var substancesTable = $('#substancesTable').DataTable({      "processing": true,      "serverSide": true,      "searching": false,      "ajax": {          "url": "/get-substances.json",          "method": "POST",          "cache": false,          "dataSrc": function (json) {               // Update non-Datatables UI elements and perform other functions based on the ajax response              $('#numSubstances').html(json.recordsTotal);              drawOptionsButton(json.isFiltering);               // Must return data for DataTables to...