Jquery DataTables serverside SyntaxError: Unexpected token <
Jquery DataTables serverside SyntaxError: Unexpected token <
我是 JS 新手,正在尝试设置数据表服务器端。按照他们的文档 here。我收到以下错误:
SyntaxError: Unexpected token <
我尝试了很多来自不同论坛的查找和推荐,但没有成功。如果有人能提供帮助,我将不胜感激。这是我的 JS:
$(document).ready(function() {
var oTable = $('#dataTables-example').dataTable({
"bServerSide": true,
"bProcessing": true,
"bJQueryUI": true,
"sAjaxSource": "ajax.php",
"fnServerData": function(sSource, aoData, fnCallback) {
/* Add some data to send to the source, and send as 'POST' */
aoData.push({
"name": "min",
"value": $('#min').val()
});
aoData.push({
"name": "max",
"value": $('#max').val()
});
$.ajax({
"dataType": 'json',
"type": "GET",
"url": "ajax.php",
"data": aoData,
"success": fnCallback,
"timeout": 15000, // optional if you want to handle timeouts (which you should)
"error": handleAjaxError // this sets up jQuery to give me errors
});
}
});
$('#min').change(function() {
oTable.fnFilter($(this).val(), 0);
});
$('#max').change(function() {
oTable.fnFilter($(this).val(), 0);
});
});
function handleAjaxError(xhr, textStatus, error) {
if (textStatus === 'timeout') {
alert('The server took too long to send the data.');
} else {
alert(error);
}
}
在我的服务器端代码中,目前我还没有覆盖 $Query
和 $Where
,所以在服务器端自定义过滤器,但我想这不应该引发错误。
<?php
$table = 'tbl_test';
$columns = array(
'DS',
'PUR',
'RegDate',
'ACTDATE',
'BUSINESS NAME',
'CITY'
);
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'samarty',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
编辑 1:Console.log
jquery.dataTables.min.js:39 Uncaught TypeError: Cannot read property 'length' of undefinedvb @ jquery.dataTables.min.js:39
(anonymous function) @ jquery.dataTables.min.js:37i @ jquery.dataTables.min.js:35j @ jquery.js:3094k.fireWith @ jquery.js:3206x @ jquery.js:8259(anonymous function) @ jquery.js:8600
数据表服务器端脚本需要 $primary_key
。我在你的代码中看不到这一点。
我是 JS 新手,正在尝试设置数据表服务器端。按照他们的文档 here。我收到以下错误:
SyntaxError: Unexpected token <
我尝试了很多来自不同论坛的查找和推荐,但没有成功。如果有人能提供帮助,我将不胜感激。这是我的 JS:
$(document).ready(function() {
var oTable = $('#dataTables-example').dataTable({
"bServerSide": true,
"bProcessing": true,
"bJQueryUI": true,
"sAjaxSource": "ajax.php",
"fnServerData": function(sSource, aoData, fnCallback) {
/* Add some data to send to the source, and send as 'POST' */
aoData.push({
"name": "min",
"value": $('#min').val()
});
aoData.push({
"name": "max",
"value": $('#max').val()
});
$.ajax({
"dataType": 'json',
"type": "GET",
"url": "ajax.php",
"data": aoData,
"success": fnCallback,
"timeout": 15000, // optional if you want to handle timeouts (which you should)
"error": handleAjaxError // this sets up jQuery to give me errors
});
}
});
$('#min').change(function() {
oTable.fnFilter($(this).val(), 0);
});
$('#max').change(function() {
oTable.fnFilter($(this).val(), 0);
});
});
function handleAjaxError(xhr, textStatus, error) {
if (textStatus === 'timeout') {
alert('The server took too long to send the data.');
} else {
alert(error);
}
}
在我的服务器端代码中,目前我还没有覆盖 $Query
和 $Where
,所以在服务器端自定义过滤器,但我想这不应该引发错误。
<?php
$table = 'tbl_test';
$columns = array(
'DS',
'PUR',
'RegDate',
'ACTDATE',
'BUSINESS NAME',
'CITY'
);
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'samarty',
'host' => 'localhost'
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
编辑 1:Console.log
jquery.dataTables.min.js:39 Uncaught TypeError: Cannot read property 'length' of undefinedvb @ jquery.dataTables.min.js:39
(anonymous function) @ jquery.dataTables.min.js:37i @ jquery.dataTables.min.js:35j @ jquery.js:3094k.fireWith @ jquery.js:3206x @ jquery.js:8259(anonymous function) @ jquery.js:8600
数据表服务器端脚本需要 $primary_key
。我在你的代码中看不到这一点。