title: Integrating DataTables with Python backend script via AJAX call
body: <p>I have a web page where I call a backend Python program via AJAX:</p>
  
  <pre><code>function runreport(datastring)
  {
          $.ajax({
                  type: "POST",
                  url:  "runprogram.py",
                  data:
                  {
                          'form_data' : datastring
                  },
                  success: function(json)
                  {
                          $("div#report_result").show();
                          alert($(json));
                          var oTable = $('#example').dataTable($(json));
                          $('html, body').animate({scrollTop:$(document).height()}, 'slow');
                  },
                  error:function(xhr,err)
                  {
                       alert("Failed\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status + "\nresponseText: "+xhr.responseText);
                  }
           });
  }
  </code></pre>
  
  <p>My requirement is to generate datasets for DataTables and then render it in the UI. The backend script returns a static sets of data:</p>
  
  <pre><code>#!/usr/local/bin/python
  
  import cgi
  import MySQLdb
  import json
  
  print "Content-Type: application/json"
  print
  
  displaylength = 5
  output = "{\n"
  output += '"iDisplayLength":' + str(displaylength) + ',\n'
  output += '"sPaginationType": "full_numbers",\n'
  output += '"bProcessing": true,\n'
  output += '"bDestroy": true,\n'
  #output += '{\n'
  output += '"aaData": [\n'
  output += '{\n'
  output += '"First Field": "First Field Value",\n'
  output += '"Second Field": "Second Field Value",\n'
  output += '"Third Field": "Third Field Value",\n'
  output += '"Fourth Field": "Fourth Field Value",\n'
  output += '"Fifth Field": "Fifth Field Value",\n'
  output += '"Sixth Field": "Sixth Field Value",\n'
  output += '"Seventh Field": "Seventh Field Value",\n'
  output += '"Eight Field": "Eight Field Value",\n'
  output += '"Nineth Field": "Nineth Field Value"\n'
  output += '},\n'
  output += '{\n'
  output += '"First Field": "First Field Value",\n'
  output += '"Second Field": "Second Field Value",\n'
  output += '"Third Field": "Third Field Value",\n'
  output += '"Fourth Field": "Fourth Field Value",\n'
  output += '"Fifth Field": "Fifth Field Value",\n'
  output += '"Sixth Field": "Sixth Field Value",\n'
  output += '"Seventh Field": "Seventh Field Value",\n'
  output += '"Eight Field": "Eight Field Value",\n'
  output += '"Nineth Field": "Nineth Field Value"\n'
  output += '}\n'
  output += ']\n'
  #output += '}\n'
  output += '"aoColumns": [\n'
  output += '{ "sTitle":"First Field", "mDataProp": "First Field" },\n'
  output += '{ "sTitle":"Second Field", "mDataProp": "Second Field" },\n'
  output += '{ "sTitle":"Third Field", "mDataProp": "Third Field" },\n'
  output += '{ "sTitle":"Fourth Field", "mDataProp": "Fourth Field" },\n'
  output += '{ "sTitle":"Fifth Field" , "mDataProp": "Fifth Field" },\n'
  output += '{ "sTitle":"Sixth Field", "mDataProp": "Sixth Field" },\n'
  output += '{ "sTitle":"Seventh Field", "mDataProp": Seventh Field" },\n'
  output += '{ "sTitle":"Eight Field", "mDataProp": "Eight Field" },\n'
  output += '{ "sTitle":"Nineth Field", "mDataProp": "Nineth Field" }\n'
  output += ']\n'
  output += '}\n'
  print output
  </code></pre>
  
  <p>But I am unable to get the desired output at UI side - is the UI / backend implementation correct?</p>