title: DataTables Ajax Error in django
body: <p>I am doing some server-side ajax loading in django.</p>
  
  <p>Here is my code clip:</p>
  
  <pre><code>@login_required
  def cmdb_list_page_server_side(request):
  #do not prepare data in view (as in  above view), data will be retrieved using ajax call (see get_countries_list below).
      return render_to_response('cmdb/list.html', locals(), context_instance = RequestContext(request))
  
  def get_cmdb_list(request):
      #prepare the params
  
      #initial querySet
      querySet = CMDB.objects.all()
      #columnIndexNameMap is required for correct sorting behavior
      columnIndexNameMap = {
          0:'envcode',
          1:'appname',
          2:'sysip',
          3   :'ostype',
          4   :'hostname',
          5   :'cpu',
          6   :'mem',
          7   :'rootdisk',
          8   :'storagetype',
          9   :'location',
          10  :'enclosure',
          11  :'position1',
          12  :'position2',
          13  :'unit',
          14  :'serviceIP',
          15  :'manufacture',
          16  :'seller',
          17  :'machinemodel',
          18  :'machinecode',
          19  :'serialnumber',
          20  :'appearance',
          21  :'archtype',
          22  :'partition',
          23  :'storagesize',
          24  :'applevel',
          25  :'domains',
          26  :'netnote',
          27  :'gateway',
          28  :'mask',
          29  :'serviceport',
          30  :'ha',
          31  :'hbIP1',
          32  :'hbIP2',
          33  :'hardwarecharge',
          34  :'systemcharge',
          35  :'appcharge',
          36  :'managegateway',
          37  :'managemask',
          38  :'repairlevel',
          39  :'repairdate',
          40  :'dbinfo',
          41  :'middlewareinfo',
          42  :'nonsysusers',
          43  :'note',
      }
      #path to template used to generate json (optional)
      jsonTemplatePath = 'cmdb/json_cmdb.txt'
  
      #call to generic function from utils
      return get_datatables_records(request, querySet, columnIndexNameMap,jsonTemplatePath)
  </code></pre>
  
  <p><strong>the file "'cmdb/json_cmdb.txt" looks like this:</strong></p>
  
  <pre><code>{
      sEcho: {{sEcho}},
      iTotalRecords: {{iTotalRecords}},
      iTotalDisplayRecords: {{iTotalDisplayRecords}},
      aaData:[
          {% for item in querySet %}
          [
              "{{ item.envcode }}",
              "{{ item.appname }}",
              "{{ item.sysip }}",
              "{{ item.ostype }}",
              "{{ item.hostname }}",
              "{{ item.cpu }}",
              "{{ item.mem }}",
              "{{ item.rootdisk }}",
              "{{ item.storagetype }}",
              "{{ item.location }}",
              "{{ item.enclosure }}",
              "{{ item.position1 }}",
              "{{ item.position2 }}",
              "{{ item.unit }}",
              "{{ item.serviceIP }}",
              "{{ item.manufacture }}",
              "{{ item.seller }}",
              "{{ item.machinemodel }}",
              "{{ item.machinecode }}",
              "{{ item.serialnumber }}",
              "{{ item.appearance }}",
              "{{ item.archtype }}",
              "{{ item.partition }}",
              "{{ item.storagesize }}",
              "{{ item.applevel }}",
              "{{ item.domains }}",
              "{{ item.netnote }}",
              "{{ item.gateway }}",
              "{{ item.mask }}",
              "{{ item.serviceport }}",
              "{{ item.ha }}",
              "{{ item.hbIP1 }}",
              "{{ item.hbIP2 }}",
              "{{ item.hardwarecharge }}",
              "{{ item.systemcharge }}",
              "{{ item.appcharge }}",
              "{{ item.managegateway }}",
              "{{ item.managemask }}",
              "{{ item.repairlevel }}",
              "{{ item.repairdate }}",
              "{{ item.note }}",
              "{{ item.dbinfo }}",
              "{{ item.middlewareinfo }}",
              "{{ item.nonsysusers }}",
          ]
              {% if not forloop.last %}
                  ,
              {% endif %}
          {% endfor %}
      ]
  }
  </code></pre>
  
  <p><strong>Finally, I got error alert window from webbrowser(Chrome) saying datatables formatting error. 
  Using firebug, i got error message as below:</strong></p>
  
  <p>P.S My ajax returning value contains Chinese. I am wondering this is the root cause.
  Ajax return as below:</p>
  
  <pre><code>{
      sEcho: 1,
      iTotalRecords: 1178,
      iTotalDisplayRecords: 1178,
      aaData:"[
  
          [
              "",
              "王晴测试机(临时)",
              "197.1.5.206",
              "windows 2003 64bit",
              "FANGLTST",
              "4",
              "32",
              "100G",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "Opsware测试",
              "197.1.4.201",
              "Redhat 64bit",
              "bsae",
              "1",
              "1",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "预留分区",
              "N/A",
              "AIX 6.1",
              "N/A",
              "4",
              "32",
              "100G",
              "",
              "兆维II",
              "ZWII-B1-08",
              "DOWN",
              "S13/14",
              "",
              "199.0.34.173",
              "IBM",
              "志鸿英华",
              "PS702",
              "8406",
              "06DB59A",
              "刀片",
              "小型机",
              "",
              "",
              "",
              "",
              "",
              "",
              "255.255.255.0",
              "0",
              "False",
              "",
              "",
              "陈晓峰/毕伟光",
              "姜晓寒",
              "张元泉",
              "199.0.34.250",
              "255.255.255.0",
              "7*24*4",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "Opsware测试",
              "197.1.4.202",
              "Redhat 64bit",
              "hpna",
              "8",
              "16",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "预留分区",
              "",
              "AIX 6.1",
              "N/A",
              "2",
              "16",
              "100G",
              "",
              "兆维II",
              "ZWII-B1-08",
              "DOWN",
              "S13/14",
              "",
              "199.0.34.173",
              "IBM",
              "志鸿英华",
              "PS702",
              "8406",
              "06DB59A",
              "刀片",
              "小型机",
              "",
              "",
              "",
              "",
              "",
              "",
              "255.255.255.0",
              "0",
              "False",
              "",
              "",
              "陈晓峰/毕伟光",
              "姜晓寒",
              "张元泉",
              "199.0.34.250",
              "255.255.255.0",
              "7*24*4",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "Opsware测试",
              "197.1.4.122",
              "",
              "opsware2",
              "0",
              "0",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "开发机",
              "197.1.4.18",
              "HPUX 11.23",
              "cmbcux1",
              "4",
              "8",
              "2*300G",
              "",
              "兆维",
              "ZW-01-01",
              "N/A",
              "",
              "U16/19",
              "197.1.7.205",
              "HP",
              "志鸿英华",
              "rx4640",
              "AB370B",
              "SGH4617B1X",
              "标准机架",
              "小型机",
              "N/A",
              "",
              "",
              "内联",
              "",
              "197.1.4.250",
              "255.255.255.0",
              "0",
              "False",
              "",
              "",
              "杨杰",
              "张立新",
              "张小龙",
              "197.1.7.250",
              "255.255.255.0",
              "N/A",
              "十一月 19, 2009",
              "sapcool1",
              "DB2 9.5.0.5",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "Opsware测试",
              "197.1.4.123",
              "",
              "opsware3",
              "0",
              "0",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
                  ,
  
  
          [
              "",
              "开发机",
              "197.1.4.24",
              "HPUX 11.23",
              "hpux3",
              "4",
              "8",
              "6*146G",
              "",
              "兆维",
              "ZW-01-01",
              "N/A",
              "",
              "U1/8",
              "197.1.7.206",
              "HP",
              "志鸿英华",
              "rx6600",
              "AD132A",
              "SGH4711KDR",
              "标准机架",
              "小型机",
              "N/A",
              "",
              "",
              "内联",
              "",
              "197.1.4.250",
              "255.255.255.0",
              "0",
              "False",
              "",
              "",
              "杨杰",
              "张立新",
              "胡汝能",
              "197.1.7.250",
              "255.255.255.0",
              "N/A",
              "四月 13, 2010",
              "None",
              "&amp;quot;DB2 9.1.0.1",
              "None",
              "None",
          ]
  
                  ,
  
  
          [
              "",
              "Opsware测试",
              "197.1.4.127",
              "",
              "opsware4bb",
              "0",
              "0",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "0",
              "False",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "",
              "None",
              "",
              "",
              "",
              "",
          ]
  
  
      ]
  }
  </code></pre>