Trying to understand JQuery logic flow

Trying to understand JQuery logic flow

Let me start by saying, I clearly don't know what I'm doing. I know just enough about JQuery to be dangerous. Currently I'm working with version 3 of foo tables, and the author provides an example of populating an html table from a .js file where he's hardcoded some rows. I'm trying to convert this hardcoding into reading data from a web service using JSON. This part I've accomplished, in the success method of JSON, if I call: alert(JSON.stringify(response)); I can see my data in the correct format.

The issue I'm having, is how to store this returned data for later use. Below is the html file I'm using:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta name="viewport" content="width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no" />
  5.     <title></title>
  6.     <link rel="stylesheet" href="../Content/bootstrap.min.css">
  7.     <script src="../Scripts/jquery-2.1.3.min.js"></script>
  8.     <script src="../Scripts/fajax.js"></script>

  9.     <link href="../Content/footable.bootstrap.min.css" rel="stylesheet" />
  10.     <script src="../Scripts/footable.min.js"></script>

  11.     <script>
  12.         jQuery(function ($) {
  13.             FAjax.defaults.delay = 1000;
  14.             $('#table_1').footable({
  15.                 ajaxEnabled: true,
  16.                 sorting: {
  17.                     enabled: true
  18.                 },
  19.                 paging: {
  20.                     enabled: true,
  21.                     total: FAjax.defaults.rows.length,
  22.                     size: 15,
  23.                     current: parseInt(FooTable.utils.getURLParameter('page')) || 1
  24.                 },
  25.                 filtering: {
  26.                     enabled: true
  27.                 },
  28.                 ajax: FAjax.request,
  29.                 columns: FAjax.defaults.columns
  30.             });
  31.         });
  32.     </script>
  33.     <style>
  34.         body
  35.         {
  36.             padding: 50px;
  37.         }
  38.     </style>
  39. </head>
  40. <body>
  41.     <table id="table_1" class="footable table table-bordered table-striped table-hover table-condensed">
  42.     </table>
  43. </body>
  44. </html>
The FAjax.js file looks like this:

  1. (function ($, FAjax) {
  2.     FAjax.eocResults = function () {
  3.         $.ajax({
  4.             type: "POST",
  5.             contentType: "application/json; charset=utf-8",
  6.             url: "../WebServices/eoc.asmx/getEOCResults",
  7.             data: "{}",
  8.             dataType: "json",
  9.             success: function (response) {
  10.                 results = response;
  11.                 alert(results);
  12.             },
  13.         })

  14.         alert("hi");

  15.         return results;
  16.     };

  17.     FAjax.defaults = {
  18.         delay: 1500,
  19.         columns: {
  20.             0: { name: 'grade', title: 'Grade', type: 'number' }
  21.         },
  22.         rows: FAjax.eocResults(),
  23.         sorters: {
  24.             text: function (a, b) {
  25.                 if (typeof (a) === 'string') { a = a.toLowerCase(); }
  26.                 if (typeof (b) === 'string') { b = b.toLowerCase(); }
  27.                 if (a === b) return 0;
  28.                 if (a < b) return -1;
  29.                 return 1;
  30.             },
  31.             number: function (a, b) {
  32.                 return a - b;
  33.             }
  34.         }
  35.     };

  36.     FAjax.isFiltered = function (query, text) {
  37.         var queries = query.split(' '), count = queries.length;
  38.         for (var i = 0, len = queries.length; i < len; i++) {
  39.             if (text.toUpperCase().indexOf(queries[i].toUpperCase()) >= 0) count--;
  40.         }
  41.         return count > 0;
  42.     };

  43.     FAjax.request = function (data) {
  44.         return $.Deferred(function (d) {
  45.             setTimeout(function () {
  46.                 var rows = JSON.parse(JSON.stringify(FAjax.defaults.rows));
  47.                 if (data.filtering && data.filtering.query) {
  48.                     var i, text, len = rows.length, remove = [];
  49.                     for (i = 0; i < len; i++) {
  50.                         text = '';
  51.                         for (var j = 0, column; j < data.filtering.columns.length; j++) {
  52.                             column = data.filtering.columns[j];
  53.                             text += ' ' + ($.isFunction(column.formatter) ? column.formatter(rows[i][column.name]) + '' : rows[i][column.name] + '');
  54.                         }
  55.                         if (FAjax.isFiltered(data.filtering.query, text)) {
  56.                             remove.push(i);
  57.                         }
  58.                     }
  59.                     remove.sort(function (a, b) { return a - b; });
  60.                     len = remove.length - 1;
  61.                     for (i = len; i >= 0; i--) {
  62.                         rows.splice(remove[i], 1);
  63.                     }
  64.                 }
  65.                 if (data.sorting && data.sorting.column && data.sorting.direction) {
  66.                     var sorter = $.isFunction(FAjax.defaults.sorters[data.sorting.column.type]) ? FAjax.defaults.sorters[data.sorting.column.type] : FAjax.defaults.sorters.text;
  67.                     rows.sort(function (a, b) {
  68.                         return data.sorting.direction == 'ASC'
  69. ? sorter(a[data.sorting.column.name], b[data.sorting.column.name])
  70. : sorter(b[data.sorting.column.name], a[data.sorting.column.name]);
  71.                     });
  72.                 }
  73.                 var total = rows.length, result = {};
  74.                 if (data.paging) {
  75.                     var start = (data.paging.current - 1) * data.paging.size,
  76. end = data.paging.current * data.paging.size > rows.length ? rows.length - 1 : data.paging.current * data.paging.size;

  77.                     if (total > data.paging.size) rows = rows.slice(start, end);
  78.                     result.paging = { total: total };
  79.                 }
  80.                 result.rows = rows;
  81.                 d.resolve(result);
  82.             }, FAjax.defaults.delay);
  83.         });
  84.     };

  85. })(jQuery, window.FAjax = window.FAjax || {});
When the function eocResults is called, I would expect that it would excute the JSON method first, wait for it to finish, the execute the alert and return commands. Obviously I'm wrong - I'm guessing it executes the JSON method but does not wait for it to finish, and immediately goes on to execute the rest of the code. When testing this, my "Hi" message pops up immediately, and then several seconds later the JSON object message displays (it takes several seconds for the data to be retrieved from the database). 

So how do I resolve this? As always, any help would be greatly appreciated!!