get invalid json response with scroll ?
get invalid json response with scroll ?
matt.crawfoord
Posts: 31Questions: 13Answers: 0
i want to load search results to jQuery datatable,i have set the scroll for query and set "deferRender": true, in my table , but why get the invalid json response !
if( !empty($requestData['_scroll_id']) )
{
$qryurl = '<ip:url>/index*/_search?search_type=scan&scroll=1m&size=20'
$data = array( .......
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $qryurl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$return = curl_exec($ch) or die(curl_error());
$array_return = json_decode($return,true);
curl_close($ch);
$hittotal = $array_return['hits']['total'];
$scroll_id = $array_return['_scroll_id'];
$source = $array_return['hits']['hits'];
$sourcecount=count($array_return['hits']['hits']);
$sourceary = array();
for($i=0;$i<$sourcecount;$i++)
{
$msgary = $array_return['hits']['hits'][$i]['_source'];
array_push($sourceary,$msgary);
}
$results = array(
"draw" => $scroll_id,
"iTotalRecords" => $hittotal,
"iTotalDisplayRecords" => $hittotal,
"aaData"=>$sourceary
);
echo json_encode($results);
javascript ,
$(document).ready(function() {
var table = $('#example').DataTable( {
"ajax": {
url : "elk_response.php",
type: 'POST',
data: {
from: "<?php echo $from; ?>",
to: "<?php echo $to; ?>",
device:"<?php echo $device; ?>",
keyword:"<?php echo $keyword; ?>",
index: "<?php echo $index; ?>"
},
},
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "datetime" },
{ "data": "message" }
],
"order": [[1, 'asc']],
"scrollY": 400,
"scrollCollapse": true,
"deferRender": true,
"paging": false,
"scroller": true
} );
Any help would be great. Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
What is the response from the server? See tech note 1 if you aren't sure how to check it.
If you could post a link to the page or use the debugger in future that would be great and save this round trip :-)
Allan
got invalid json response , I think is first query problem ,datatable how to get the first result ??$_REQUEST first time should be empty ? right ?
Yes. What was it? Normally an error message or similar might be shown.
No. In your above configuration it should contain your four defined parameters.
Allan
contain my four defined parameters???? Are you mean i have to predefined four value in $_REQUEST ?
No. You use
ajax.data
above to define five parameters (sorry - I miss-read the indentation I should have said five not four). They arefrom
,to
,device
, etc. They should be present in the Ajax request submitted to the server (and therefore in PHP's $_REQUEST super global).Allan
Hi allan,
can you help me to solve the problem https://datatables.net/forums/discussion/35956/datatables-search-child-row-content-and-child-row-field-name#latest
The DataTables support options are available if you need to be assured of me being able to spend my time answering questions.
Allan
hi allan,
can you help me to solve the problem https://datatables.net/forums/discussion/36183/jquery-datatables-only-can-get-10-records#latest