title: Client side scripting for DataTables Server Side Scripting
body: <p>I am writing a code for server side processing for DataTables. I have a UI page where I collect all user input like start / end dates, token ID, batch Id etc. Now I have to pass these values to backend script and run a query and render output to datatables in UI page.</p>
  
  <p>So I have the JS code to take and validate user input but I am not sure how to call / set params for datatables to state server side scripting. Below is my script:</p>
  
  <pre><code>function runreport(datastring)
  {
         var oTable = $('#example').dataTable( {
                  "bProcessing": true,
                  "bServerSide": true,
                  "sAjaxSource": "runsearch.py",
                  "bDestroy" : true,
                  "fnServerData": function ( sSource, aoData, fnCallback ) {
                          $.ajax( {
                                          "dataType": 'json',
                                          "type": "POST",
                                          "url": sSource,
                                          "data": aoData,
                                          "success": function(json) {
                                                  $("div#report_result").show();
                                                  $('html, body').animate({scrollTop:$(document).height()}, 'slow');
                                                  fnCallback(json);
                                          }
                                  } );
                   }
          } );
  }
  </code></pre>
  
  <p>I call 'runreport' method when all input params are validated. I construct datastring as like query string : token_id=xxxx&amp;email_id=asdsad@jj.com&amp;start_date=1212121212&amp;end_date=98989898 but these values are not getting passed? I get the below error:</p>
  
  <pre><code>k is undefined
  [Break On This Error]  
  
  ...Sorting=="undefined"&amp;&amp;typeof e.saved_aaSorting=="undefined")e.aaSorting[a][1]=k....
  
  jquery....min.js (line 150)
  </code></pre>
  
  <p>What we should do to have DataTables result generated from a backend script?</p>
  
  <p>I am not getting the result output as desired? Is this the right way to call DataTables functionality for server side processg?</p>
  
  <p>Below is my Python code that dumps static result set:</p>
  
  <pre><code>#!/usr/local/bin/python
  
  import cgi
  import MySQLdb
  import json
  
  print "Content-Type: application/json"
  print
  
  displaylength =5
  result = {'iDisplayLength':str(displaylength), 'sPaginationType':'full_numbers', 'bProcessing':1, 'bDestroy': 1, 'bRetrieve':1, 'aaData':[{'First Field':'First Field Value', 'Second Field':'Second Field Value', 'Third Field':'Third Field Value', 'Fourth Field':'Fourth Field Value', 'Fifth Field':'Fifth Field Value', 'Sixth Field':'Sixth Field Value', 'Seventh Field':'Seventh Field Value', 'Eight Field':'Eight Field Value', 'Nineth Field':'Nineth Field Value'}, {'First Field':'First Field Value', 'Second Field':'Second Field Value', 'Third Field':'Third Field Value', 'Fourth Field':'Fourth Field Value', 'Fifth Field':'Fifth Field Value', 'Sixth Field':'Sixth Field Value', 'Seventh Field':'Seventh Field Value', 'Eight Field':'Eight Field Value', 'Nineth Field':'Nineth Field Value'}], 'aoColumns':[{'sTitle':'First Field', 'mDataProp': 'First Field'},{ 'sTitle':'Second Field', 'mDataProp': 'Second Field'}, {'sTitle':'Third Field', 'mDataProp': 'Third Field' }, { 'sTitle':'Fourth Field', 'mDataProp': 'Fourth Field' }, { 'sTitle':'Fifth Field' , 'mDataProp': 'Fifth Field' }, { 'sTitle':'Sixth Field', 'mDataProp': 'Sixth Field' }, { 'sTitle':'Seventh Field', 'mDataProp': 'Seventh Field' }, { 'sTitle':'Eight Field', 'mDataProp': 'Eight Field' }, { 'sTitle':'Nineth Field', 'mDataProp': 'Nineth Field' }]}
  
  json_string = json.dumps(result)
  print json_string
  </code></pre>