JQuery 数据表卡住“正在从服务器加载数据”在 IE7、IE8、IE9 中使用 JSON
我在客户端管理面板上使用 Jquery Datatables,我测试了所有内容,它在 Chrome、FF、Opera 中运行完美,但是当我尝试使用 IE7、8 或 9 加载它时,它只是停留在“从服务器加载数据”
这里是我的 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 );
?>
I am using Jquery Datatables on a clients admin panel, I tested everything and it worked perfect in Chrome, FF, Opera but when I try loading it with IE7, 8 or 9 it just sticks on "loading data from server"
Here is my JSON which validates ok
{
"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"
]
]
}
Here is my server_processing.php file (file that generates the json code)
<?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 );
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 ie8+ 上按 F-12 并打开脚本控制台。可能存在您看不到的错误。
另外,无需发布服务器端代码,因为这是客户端问题。
Press F-12 on ie8+ and open the Script console. There may be an error you can't see.
Also, no need to post your server-side code since this is a client-side problem.
对于其他遇到类似问题的人,我找到了解决方案。
在 data_processing.php 文件中,我将单引号更改为双引号,现在它可以在 IE7 和 8 中使用
for anyone else having similar problems I found a fix.
In the data_processing.php file I changed the single quotes to double quotes and now it works in IE7 and 8
http://datatables.net/ 这可能会有所帮助..而且你也可以学到一些东西......
http://datatables.net/ this might help.. And also u can learn something also.....