我在客户端管理面板上使用Jquery Datatables,我测试了一切,它在Chrome,FF,Opera中运行得很完美但是当我尝试用IE7,8或9加载时它只是坚持“从服务器加载数据”< / p>
这是我的JSON验证确定
{
"sEcho":0,
"iTotalRecords":"5",
"iTotalDisplayRecords":"5",
"aaData":[
[
"<a >1783<\/a><a ><img ><\/a>",
"2011-03-12 03:42:06",
"tommy arnold",
"30.00",
"Post",
"Unpaid",
"Incomplete"
],
[
"<a >1797<\/a><a ><img ><\/a>",
"2011-03-15 17:08:09",
"tommy arnold",
"130.00",
"Post",
"Unpaid",
"Incomplete"
],
[
"<a >1798<\/a><a ><img ><\/a>",
"2011-03-15 17:12:04",
"tommy arnold",
"137.00",
"Post",
"Unpaid",
"Incomplete"
],
[
"<a >1799<\/a><a ><img ><\/a>",
"2011-03-15 17:12:34",
"tommy arnold",
"58.00",
"Post",
"Unpaid",
"Incomplete"
],
[
"<a >1800<\/a><a ><img ><\/a>",
"2011-03-15 17:13:00",
"tommy arnold",
"91.00",
"Post",
"Unpaid",
"Incomplete"
]
]
}
这是我的server_processing.php文件(生成json代码的文件)
<?php
include"../inc/config.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( 'ID', 'date', 'address_name', 'total', 'paymentOption', 'payment_status', 'orderStatus');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "ID";
/* DB table to use */
$sTable = "orders";
/* Database connection information */
$gaSql['user'] = $dbuser;
$gaSql['password'] = $dbpass;
$gaSql['db'] = $dbname;
$gaSql['server'] = $dbhost;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
/*
* SQL queries
* Get data to display
*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable
";
$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* Output
*/
$output = array(
//"sEcho" => intval($_GET['sEcho']),
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] == "version" )
{
/* Special output formatting for 'version' column */
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
}
elseif ( $aColumns[$i] === "ID" )
{
/* Special output formatting for 'name' column */
$row[] = '<a href="invoice.php?ORDERID='. $aRow[ $aColumns[$i] ]. '" target="_blank" title="'. 'View Invoice: '. $aRow[ $aColumns[$i] ]. '">'. $aRow[ $aColumns[$i] ]. '</a><a href="invoice.php?action=delete&ORDERID='. $aRow[ $aColumns[$i] ]. '" onClick="return confirm(\'Are you sure you want to delete?\')"><img src="../images/icons/trash-can-delete.png" width="16" height="16"></a>';
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$row[] = $aRow[ $aColumns[$i] ];
}
}
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>
答案 0 :(得分:0)
按ie8 +上的F-12并打开脚本控制台。您可能看不到错误。
此外,无需发布服务器端代码,因为这是客户端问题。
答案 1 :(得分:0)
对于遇到类似问题的其他人我找到了解决办法。
在data_processing.php文件中,我将单引号更改为双引号,现在它可以在IE7和8中使用
elseif ( $aColumns[$i] === "ID" )
{
$row[] = "<a href=\"invoice.php?ORDERID=".$aRow[ $aColumns[$i] ]."\" target=\"_blank\" title=\"View Invoice: ".$aRow[ $aColumns[$i] ]."\">".$aRow[ $aColumns[$i] ]."</a><a href=\"invoice.php?action=delete&ORDERID=".$aRow[ $aColumns[$i] ]."\"onClick=\"return confirm('Are you sure you want to delete?')\"><img border=\"0\" src=\"../images/icons/trash-can-delete.png\" width=\"16\" height=\"16\"></a>";
}
答案 2 :(得分:-2)
http://datatables.net/这可能会有所帮助..而且你也可以学到一些东西......