jquery - Datatables server side processing invalid Json -


alright working on script datatables server side processing , ran error. whenever load page alert saying json invalid. though i've used jsonlin validate , said json valid.

so here json use testing:

 { "draw": 1, "recordstotal": 5, "recordsfiltered": 5, "data": [{ "first_name": "airi", "last_name": "satou", "position": "accountant", "office": "tokyo" }, { "first_name": "garrett", "last_name": "winters", "position": "accountant", "office": "tokyo" }, { "first_name": "rhona", "last_name": "davidson", "position": "integration specialist", "office": "tokyo" }, { "first_name": "sakura", "last_name": "yamamoto", "position": "support engineer", "office": "tokyo" }] } 

and datatable script

 $(document).ready(function() {      var dbcolumns = getcolumns("<?php echo $view; ?>",'proccestable', "<?php echo base_url(); ?>", "<?php echo $viewaction; ?>");      $('#proccestable').datatable( {         "processing": true,         "serverside": true,         "ajax":{             url: ' <?php echo base_url("admin/qajaxcall/".$ajaxaction."/".$tablename); ?>',             type: "post",             datatype: "jsonp",             data: { data : dbcolumns}         },     "columns": [         { "data": "first_name" },         { "data": "last_name" },         { "data": "position" },         { "data": "office" }     ]     }); }); 

in post try else isn't doing json being returned. though i've noticed, there null @ end of json? how return json datatable:

 $array = '{      "draw": 1,      "recordstotal": 5,      "recordsfiltered": 5,       "data": [{          "first_name": "airi",          "last_name": "satou",          "position": "accountant",          "office": "tokyo"      }, {          "first_name": "garrett",          "last_name": "winters",          "position": "accountant",          "office": "tokyo"      }, {           "first_name": "rhona",           "last_name": "davidson",           "position": "integration specialist",          "office": "tokyo"      }, {          "first_name": "sakura",          "last_name": "yamamoto",          "position": "support engineer",          "office": "tokyo"      }]        }';         echo $array; 

i dont use echo json_encode($array) since variable json already. there reason "null" being sent aswell??

you can use datatable library codeigniter in order make correct json response. so, easy rather creating response manually.

  1. https://github.com/igniteddatatables/ignited-datatables
  2. https://github.com/zepernick/codeigniter-datatables

thanks


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -