Issue with Server-Side Data (json error depending on content of sSearch)
Issue with Server-Side Data (json error depending on content of sSearch)
ArcNovus
Posts: 7Questions: 0Answers: 0
Hello
i'm using datatables within a selfwritten crm with "large" amounts of data ( 30'000+ rows per table, 80+ tables ). Everything works very fine so far, but one small bug i noticed.
As i use the search filter ( Search: ) to filter the results, it works correctly for queries "j" and " jn2" but not for "jn" .. but its not about sSearch = 2, because e.G "li" is working or "jp" too .. also queries with umlauts are working e.G "
i'm using datatables within a selfwritten crm with "large" amounts of data ( 30'000+ rows per table, 80+ tables ). Everything works very fine so far, but one small bug i noticed.
As i use the search filter ( Search: ) to filter the results, it works correctly for queries "j" and " jn2" but not for "jn" .. but its not about sSearch = 2, because e.G "li" is working or "jp" too .. also queries with umlauts are working e.G "
This discussion has been closed.
Replies
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
and so in qry file $_GET replaced with $_POST .. did not change
not working
http://78.46.124.50/not_working.png
http://78.46.124.50/not_working2.png
working
http://78.46.124.50/working.png
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
//$sOutput .= '"'.addslashes($aRow['article_nr']).'",';
$sOutput .= '"'.addslashes(''.$aRow['article_nr'].'').'",';
$sOutput .= '"'.addslashes($aRow['supplier_article_nr']).'",';
$sOutput .= '"'.addslashes($aRow['name']).'",';
//if($aRow['tag_brand'] != 0) {
// $tagData = $companyDB->getRowAssoc('tag_tags','`ID` = '.$aRow['tag_brand']);
// $sOutput .= '"'.addslashes($tagData['label']).'",';
//} else {
$sOutput .= '"-",';
//}
//$sOutput .= '"'.addslashes($aRow['tag_brand']).'",';
if($userHasEditPermission){
$sOutput .= '"'.addslashes('').'"';
}else{
$sOutput .= '"'.addslashes(' ').'"';
}
$sOutput .= "],";
}
Thanks for all the information - very useful.
> Error is "DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
This error message means more or less way it says - the return string isn't strictly a JSON object. If you grab the return from the server and pass it through http://jsonlint.com you'll be able to see where the parsing error is.
My guess is that you've got a newline character somewhere, which just so happens to match the 'jn' filter (if you were to page through the whole table you'd come across it as well). So somewhere in the DB there is a row which doesn't convert to nice JSON when using addslashes and a new line character is my guess...
If you have PHP 5.2+ on your server I'd suggest using json_encode() as this makes dealing with JSON much easier in PHP - like my example here: http://www.datatables.net/development/server-side/php_mysql .
Regards,
Allan
thanks for your answer. Your Tip with jsonlint.com helped me and brought me to the soliution.
Removed addslashes() function from sOutput lines. The error was a slashed \' ..now as ' its working.
Thanks a lot for your help, i'm honestly greatful for such good work as datatables, so much time
i can spend in other parts of my app =)
Good to hear you got it sorted - and my pleasure :-). Great to hear that DataTables is proving to be useful!
Regards,
Allan
I have the same problem after upgrading my jQuery version to the latest version.
The \' was causing the datatable to crash. JsonLint also showed the problem with having a forward slash.
Unfortunately however removing addslashes has not resolved my issue. Even more confusing is that JsonLint says the json with a single quote ' is valid. However datatables is still crashing.
I tried upgrading to the latest version of datatables but still no luck.
I would greatly appreciate some other ideas?
Thanks,
Tim
http://stackoverflow.com/questions/2275359/jquery-single-quote-in-json-response
Allan
After insert and delete the datagrid is not working can you give any idea..
oTable.fnDraw();
After insert and delete the datagrid is not working can you give any idea..
oTable.fnDraw();
How does this relate to the original thread? You are going to have to give a lot more information than "Redraw is not working"...