title: DataTables Error: "Requested unknown parameter"
body: <p>I'm new to the DataTables jquery plugin.  After discovering that IE 8 had performance issues with Javascript I decided to change the way I use DataTables to do server side processing.  I'm getting this error message when my JSP loads ( I'm using Spring 3 ):</p>
  
  <pre><code>DataTables warning (table id = 'results_table'): Requested unknown parameter '0' from the data source for row 0
  </code></pre>
  
  <p>I Googled around and found that many causes of that error message come down to malformed JSON so I found a way to output my JSON from my Spring 3 controller function to take a look at the JSON it makes and I changed my code to get it to be pretty close to what the <a href="http://datatables.net/usage/server-side" rel="noreferrer">DataTables</a> site says it should look like.</p>
  
  <p>Still no joy, still getting that error message.</p>
  
  <p>The server side processing examples I found for DataTables didn't include code for specifying the columns used on the client side, so I assumed I don't need it.  Do I?</p>
  
  <p><strong>Here are the relevant parts of my results.jsp:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  
  &lt;head&gt;
      &lt;title&gt;ACME: search results in a nice DataTables.net Plugin&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" /&gt;
  &lt;script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery-1.7.js"&gt;&lt;/script&gt;
  &lt;script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery.dataTables.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
      $('#results_table').dataTable( {
          "bProcessing": true,
          "bServerSide": true,
          "sScrollX": "600px",
          "sServerMethod": "POST",
          "sAjaxSource": "/acme/resultstable",
      } );
  } );
  &lt;/script&gt;
  
  
  &lt;form id="command" name="f" action="employee" method="post"&gt;
  
      &lt;div id = "results"&gt;
          &lt;table id = "results_table"&gt;
              &lt;thead&gt;           
                  &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                      &lt;th&gt;ID&lt;/th&gt;
                      &lt;th&gt;NO_PRINT&lt;/th&gt;
                      &lt;th&gt;Full Name&lt;/th&gt;
                      &lt;th&gt;Email Address&lt;/th&gt;
                      &lt;th&gt;Phone Number&lt;/th&gt;
                      &lt;th&gt;Organization&lt;/th&gt;
                      &lt;th&gt;Organization Code&lt;/th&gt;
                      &lt;th&gt;Position&lt;/th&gt;
                      &lt;th&gt;Employee Type&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;           
              &lt;/tbody&gt;
          &lt;/table&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Here is the JSON response I've been sending to it:</strong></p>
  
  <pre><code>{
    "sEcho" : 1,
    "iTotalRecords" : 1,
    "iTotalDisplayRecords" : 1,
    "aaData" : [ {
      "person_id" : "888888",
      "ID" : "999999",
      "no_print" : "&amp;nbsp;",
      "fullname" : "Obama, Willard",
      "email_address" : "&lt;a href = \"mailto:barry@whitehouse.gov\"&gt;barry@whitehouse.gov&lt;/a&gt;",
      "current_phone_number" : "303-867-5309",
      "title" : "&amp;nbsp;",
      "office" : "&amp;nbsp;",
      "position" : "Contractor",
      "empl_code" : "CONT"
    } ]
  }
  </code></pre>
  
  <p>Here is my Spring controller function I am using to send the JSON response via Jackson.  This includes code to output my JSON so I can see what it looks like.  Could the JSON it outputs to stdout and what I am sending back to DataTables be different?</p>
  
  <pre><code>@RequestMapping(value = "/resultstable", method = RequestMethod.POST)
  public @ResponseBody LinkedHashMap resultstable(ModelMap model,                 
                                                  HttpSession session,
                                                  @RequestParam (required=true) int sEcho,   
                                                  @RequestParam (required=true) int iDisplayStart,   
                                                  @RequestParam (required=true) int iDisplayLength,    
                                                  @RequestParam (required=true) int iColumns,
                                                  @RequestParam (required=true) int iSortCol_0, 
                                                  @RequestParam (required=false)String sSortDir_0,
                                                  @RequestParam (required=true) String sSearch ) {
  
      /*
      **********************************************************************
      **  These come from the DataTables.net Jquery plugin on results.jsp
      **********************************************************************
      **  sEcho,          -  just send it back, used by DataTables for synching
      **  iDisplayStart   -  index of the record to start with, ie 3 for the 3rd of 100 records
      **  iDisplayLength  -  number of records to send back starting with iDisplayStart  
      **  iColumns        -  number of columns to be displayed in the table
      **  iSortCol_0      -  the number of thee column to be sorted on
      **  sSortDir_0      -  direction of sorting: asc or desc
      **  sSearch         -  from the search box, filter results further on this term 
      ********************************************************************** 
      */
  
      String nextView                   = "results";
      String usertype                   = (String)session.getAttribute("usertype");
      Search search                     = new Search(usertype);
      List&lt;LinkedHashMap&gt; records       = null;
      String results                    = null;
      int number_of_records             = (Integer)session.getAttribute("number_of_records_found");
      ResultsView rv                    = new ResultsView();
      ResultsScreenTableHolder rstrh    = null;
      SearchScreenDataHolder ssdh2      = (SearchScreenDataHolder)session.getAttribute("search_screen_data_holder");
      ObjectMapper mapper               = new ObjectMapper();
  
      logger.debug("started");
  
      logger.debug("sEcho,         == " + sEcho         );
      logger.debug("iDisplayStart  == " + iDisplayStart  );
      logger.debug("iDisplayLength == " + iDisplayLength );
      logger.debug("iColumns       == " + iColumns       );
      logger.debug("iSortCol_0     == " + iSortCol_0     );
      logger.debug("sSortDir_0     == " + sSortDir_0     );
      logger.debug("sSearch        == " + sSearch        );
  
  
      try {
          records = search.searchForAnEmployee(ssdh2,usertype,sSearch,"asc",
                                               iSortCol_0,iDisplayStart, 
                                               iDisplayLength);    
  
  
          LinkedHashMap lhm= new java.util.LinkedHashMap();
          lhm.put("sEcho", sEcho);
          lhm.put("iTotalRecords",number_of_records);
          lhm.put("iTotalDisplayRecords",9);
          lhm.put("aaData",records);
  
          // convert user object to json string, and save to a file
          mapper.writeValue(new File("c:\\Downloads\\rstrh.json.txt"), lhm);
  
          // display to console
          logger.debug("My JSON: " + mapper.defaultPrettyPrintingWriter().writeValueAsString(lhm));
  
      }
      catch (Exception e) {
          logger.debug("\n",e);
      }
  
      return lhm;       
  
  }// end function 
  </code></pre>