title: How to fetch data from MSSQL Query for DataTables using Ajax
body: <p>This is the code that i get from <a href="http://www.datatables.net/examples/api/row_details.html" rel="nofollow">DataTables Child Rows</a></p>
  
  <pre><code>$(document).ready(function() {
      var table = $('#example').DataTable( {
          "ajax": "../ajax/data/objects.txt", //here
          "columns": [
              {
                  "className":      'details-control',
                  "orderable":      false,
                  "data":           null,
                  "defaultContent": ''
              }, //and here to fetch the data below
              { "data": "name" }, 
              { "data": "position" }, 
              { "data": "office" },
              { "data": "salary" }
          ],
          "order": [[1, 'asc']]
      } );
  </code></pre>
  
  <p>I would like to get the data from an SQL Query by using ajax. This is my SQL Query :</p>
  
  <pre><code>$tsql = 
  "SELECT *
  FROM [dbo].[ITEM_MASTER] A
  INNER JOIN
  [dbo].[STOCK] B
  ON
  B.ItemId = A.ItemId
  ";
  $result = sqlsrv_query($conn, $tsql, array(), array( "Scrollable" =&gt; SQLSRV_CURSOR_KEYSET ));
  if (!$result) {
   die("Query to show fields from table failed");
  }
  
  while($row=sqlsrv_fetch_array($result))
  {
      $ItmId = $row['ItemId'];
      $ItmName = $row['ItemName'];
      $ItmType = $row['ItemType'];
      $ItmGroup = $row['ItemGroup'];
      $ItmClass = $row['ItemClass'];
      $ItmSerialNum = $row['ItemSerialNum'];
      $ItmUOM = $row['ItemUOM'];
      $StkQty = $row['StockQuantity'];
      $StkId = $row['StockId'];
   }
  </code></pre>
  
  <p>And on the ajax part, i just call the name of the variable like <code>$ItmId</code> or like i've stated in my while loop.
  Is it possible? If so, how? Since i don't have any knowledge on AJAX</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The data were pushed to the second parameter and is not showing the <code>ItmId</code> ? And no matter if i change <code>$data : ItmName</code> it just displays based on the arrays and display something else?</p>
  
  <pre><code>$(document).ready(function() {
      var table = $('#table').DataTable( {
          "ajax": {
              "url": "table_data.php",
              "type": "POST"
              },
          "columns": [
              {
                  "class":          'details-control',
                  "orderable":      false,
                  "data":           null,
                  "defaultContent": ''
              },
              { "$data": "ItmId"  },
              { "$data": "ItmName" },
              { "$data": "ItmGroup"},
              { "$data": "ItmClass"}
      ],
          "order": [[1, 'asc']]
      } );
  </code></pre>