Datatables not work
Datatables not work
danish123_123
Posts: 3Questions: 1Answers: 0
On page load ,i send a ajax request and get a table from the server.I receive the ajax request in php and get the data from the database and embet it with table and send the response by using echo json_encdoe($form)
I'm using datatables with this form but it's not work
This discussion has been closed.
Answers
$form = '';
$form .= '<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">';
$form .= '
';
// $form .= '';
$form .= '';
$form .= '';
$form .= "jQuery(document).ready(function($){"; $form .= "$('#select_all').on('click',function(){"; $form .= "if(this.checked){"; $form .= "$('.checkbox').each(function(){"; $form .= "this.checked = true;"; $form .= "});"; $form .= "}else{"; $form .= "$('.checkbox').each(function(){"; $form .= "this.checked = false;"; $form .= " });"; $form .= "}"; $form .= " });"; $form .= "});"; $form .= "jQuery('#select_all_form').on('submit',function(e){"; $form .= "e.preventDefault();"; $form .= "var form = $(this);"; $form .= "$.ajax({"; $form .= "url : base_url + 'home/bulkaction',"; $form .= "type: 'POST',"; $form .= "data : form.serialize(),"; $form .= "dataType: 'json',"; $form .= "success:function(res){"; $form .= "if(res.status == 'true'){"; $form .= "alert(res.msg);"; $form .= "$('#select_all_form')[0].reset();"; $form .= "}else{"; $form .= "alert(res.msg);"; $form .= "}"; $form .= "}"; $form .= "});"; $form .= ""; $form .= "$.ajax({"; $form .= "url : base_url + 'home/get_data',"; $form .= "type: 'GET',"; $form .= "dataType: 'json',"; $form .= "success: function(res){"; $form .= "$('#table_data').html(res);"; $form .= "}"; $form .= "});"; $form .= ""; $form .= "$('#mydatatable').DataTable();"; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= "});"; $form .= "";
echo json_encode($form);
Please use markdown to highlight your code. See below.
http://webhookdanish.000webhostapp.com/datatable.txt
Here is the link of my code
Why are you encoding Javascript as JSON? That won't work unless you are using
eval
or something similarly unsafe on the client-side?I don't really get what the code is trying to do I'm afraid. If you could link to a test case (per the forum rules) that would be useful.
Allan