Server Side Error
Server Side Error
Hodeitxo
Posts: 16Questions: 0Answers: 0
Hi all!
Im a newbie on DataTables, so be patient please.
Im trying to use server side example for my web, but when i change data on code, only mysql info, ive this ERROR:
DataTAbles warning(table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
Anybody knows how to fix it?
Thanks! And sorry about my english, im spanish and i'm trying to write as clear as posible :D
Im a newbie on DataTables, so be patient please.
Im trying to use server side example for my web, but when i change data on code, only mysql info, ive this ERROR:
DataTAbles warning(table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
Anybody knows how to fix it?
Thanks! And sorry about my english, im spanish and i'm trying to write as clear as posible :D
This discussion has been closed.
Replies
Here's the top part of one of mine: [code] /*
* Script: DataTables server-side script for PHP and MySQL
* Copyright: 2010 - Allan Jardine
* License: GPL v2 or BSD (3-point)
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$plyrno = $_GET['playerno'];
$aColumns = array( 'ahID', 'ahseasonID', "ahT", 'ah1stXV', 'ah2ndXV', 'ah3rdXV', 'ah4thXV', 'ah5thXV', 'ahOthXV', 'jnrapps', 'ahplayerID');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "ahID";
/* DB table to use */
$sTable = "apphistory";
$sTable = $sTable . ' WHERE (' . $sTable . '.ahplayerID = ' . $plyrno . ')';
include('include/conn.php'); [/code]
One of the most important parts is that the array or columns must match the number of columns in your html table.
Allan
http://live.datatables.net/usopol/edit#javascript,html,live
PeteB, my code is different, so i can't use yours, but thank you anyway.
Allan, i'm using the example code from the web and i only change the connection info. If you need this info, i can give you by a message. Thank you!
Allan
[code]<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array( 'FechaActa', 'AñoActa', 'Signatura', 'Organo', 'Pagini' );
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "Num";
/* DB table to use */
$sTable = "Actas";
/* Database connection information */
$gaSql['user'] = "*";
$gaSql['password'] = "*";
$gaSql['db'] = "*";
$gaSql['server'] = "*";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i[/code]
[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
DataTables example
@import "../../media/css/demo_page.css";
@import "../../media/css/demo_table.css";
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/scripts/server_processing.php";
} );
} );
DataTables server-side processing example
Customer_Ticket_No
Loading data from server
prueba1
prueba1
prueba1
prueba1
prueba1
[/code]
Here:
[code]
"sAjaxSource": "/scripts/server_processing.php";[/code]
This is JSON, use a validator to check your JSON, and listen to your browser's complains.
http://jsonlint.com/
I haven't got a JSon Code, im getting data from a MySQL tables. By the moment, the error of JSon dissapear, but data from MySQL didnt load. Any idea?
About the not loading data, check in the console if the post went through, and what is the response.
If the response is empty, then it's just a problem on your php script.
[code] "sAjaxSource": "/scripts/server_processing.php";[/code]
to this:
[code] "sAjaxSource": "/scripts/server_processing.php"[/code]
The last line doesn't need ; or ,
It's what let the plugin knows not to expect any more parameters.
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/scripts/server_processing.php"
} );
} );
[/code]
And Browser's error says that it waits } on line of "sAjaxSource", but i have 2 } for close function.
http://debug.datatables.net/oqebij
Allan
Typically in /var/log/apache/error_log on your server. Either that or make sure PHP is set to output errors.
Yes you are using Allan's Server-side code which was my first question and there's a mysql_error() implemented on it, my guess is then your select is not faulty, but it's just malformed or the parameters you are passing return nothing from the database.
But it would still return something.. Hum.
Allan
[code]
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array( 'dato1', 'dato2', 'dato3', 'dato4', 'dato5' );
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "dato1";
/* DB table to use */
$sTable = "prueba";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "tablas_urnieta";
$gaSql['server'] = "localhost:3306";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
That looks a bit dodgy - you need to json_encode() it.
Also can you run your table through the debugger if the script it returning data (i.e. you can see it in Firebug) but still now working.
Thanks all :D
As I said - can you run it throughout he debugger again please if it isn't working.