Jquery DataTables服务器端语法错误:意外的标记<

Jquery DataTables serverside SyntaxError: Unexpected token <

本文关键字:lt 意外 服务器端 DataTables 语法 错误 Jquery      更新时间:2024-03-04

我是JS新手,尝试在服务器端设置数据表。在这里遵循他们的文档。我得到以下错误:

SyntaxError:意外的标记<

我尝试了许多不同论坛的查找和推荐,都没有成功。如果有人能帮忙,我真的很感激。这是我的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。我在你的代码中看不到。