Ajax, Few Problems
Ajax, Few Problems
Here is a test page for you:
http://fogest.com/test/
As you see, it throws an error, and simply does not work.
JS:
[code]
$(document).ready(function() {
$('#trades').dataTable( {
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"bProcessing": true,
"bServerSide": true,
"aoColumns": [
{ "mData": "id" },
{ "mData": "Minecraft_Username" },
{ "mData": "Block_Name" },
{ "mData": "Quantity" },
{ "mData": "Cost" },
{ "mData": "Trade_Status" },
],
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.php"
} );
} );
[/code]
And the test.php source:
[code]
<?php
$tableName = "mctrade_trades";
$result = mysql_query("SELECT `id`, `Minecraft_Username`, `Block_Name`, `Quantity`, `Cost`, `Trade_Status` FROM $tableName");
$data = array();
while ( $row = mysql_fetch_assoc($result) )
{
$data[] = $row;
$output['aaData'][] = $row;
}
//$output['aaData'][] = $row;
header("Content-type: application/json");
echo json_encode( $output );
?>
[/code]
Tables:
[code]
Trade ID
Minecraft Username
Item
Quantity
Price
Trade Status(opened/closed)
[/code]
Output of the test.php:
http://fogest.com/test/test.php
What am I doing wrong?
http://fogest.com/test/
As you see, it throws an error, and simply does not work.
JS:
[code]
$(document).ready(function() {
$('#trades').dataTable( {
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"bProcessing": true,
"bServerSide": true,
"aoColumns": [
{ "mData": "id" },
{ "mData": "Minecraft_Username" },
{ "mData": "Block_Name" },
{ "mData": "Quantity" },
{ "mData": "Cost" },
{ "mData": "Trade_Status" },
],
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.php"
} );
} );
[/code]
And the test.php source:
[code]
<?php
$tableName = "mctrade_trades";
$result = mysql_query("SELECT `id`, `Minecraft_Username`, `Block_Name`, `Quantity`, `Cost`, `Trade_Status` FROM $tableName");
$data = array();
while ( $row = mysql_fetch_assoc($result) )
{
$data[] = $row;
$output['aaData'][] = $row;
}
//$output['aaData'][] = $row;
header("Content-type: application/json");
echo json_encode( $output );
?>
[/code]
Tables:
[code]
Trade ID
Minecraft Username
Item
Quantity
Price
Trade Status(opened/closed)
[/code]
Output of the test.php:
http://fogest.com/test/test.php
What am I doing wrong?
This discussion has been closed.
Replies
For that few rows though, I'd suggest you don't use server-side processing - there is no need.
Allan