jquery datatables mysql jsp DataTables错误DataTables警告:无法解析JSON数据

时间:2014-02-18 16:30:21

标签: jquery mysql json jsp datatables

我想在jsp和mysql中使用jquery liberary数据表。 我已经尝试了基于jsp的服务器端处理示例(https://datatables.net/development/server-side/jsp)并收到错误消息:

  

DataTables警告(table id ='example'):DataTables警告:JSON   无法解析来自服务器的数据。这是由JSON引起的   格式化错误。

该示例包含一个mysql数据库和一个应该在服务器端运行的.jsp上的源代码。 不包括应该调用serverside .jsp以提供包含数据库内容的json消息的客户端, 所以我对simular .php示例的客户端做了一些调整。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="shortcut icon" type="image/ico" href="http://www.sprymedia.co.uk/media/images/favicon.ico" />

        <title>DataTables example23</title>
        <style type="text/css" title="currentStyle">
            @import "media/css/demo_page.css";
            @import "media/css/demo_table.css";
        </style>
        <script type="text/javascript" language="javascript" src="media/js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="media/js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() 
                    {
                $('#example').dataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "server_side_processing.jsp"
                } );
            } );
        </script>
    </head>
    <body id="dt_example">
        <div id="container">
            <div class="full_width big">

            </div>
        <div id="dynamic">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th width="20%">Rendering engine</th>
            <th width="25%">Browser</th>
            <th width="25%">Platform(s)</th>
            <th width="15%">Engine version</th>
            <th width="15%">CSS grade</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="5" class="dataTables_empty">Loading data from server</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>Rendering engine</th>
            <th>Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
        </tr>
    </tfoot>
</table>
            </div>
            <div class="spacer"></div>


            <div id="footer" style="text-align:center;">
                <span style="font-size:10px;">DataTables &copy; Allan Jardine 2008-2010</span>
            </div>
        </div>
    </body>
</html>

错误表明,json解析存在问题。 因此,我使用firebug来查看服务器的json响应。 结果如下:

{"iTotalDisplayRecords":57,
"iTotalRecords":57,
"aaData":[
["Gecko","Firefox 1.0","Win 98+ \/ OSX.2+","1.7","A"],
["Gecko","Firefox 1.5","Win 98+ \/ OSX.2+","1.8","A"],
["Gecko","Firefox 2.0","Win 98+ \/ OSX.2+","1.8","A"],
["Gecko","Firefox 3.0","Win 2k+ \/ OSX.3+","1.9","A"],
["Gecko","Camino 1.0","OSX.2+","1.8","A"],
["Gecko","Camino 1.5","OSX.3+","1.8","A"],
["Gecko","Netscape 7.2","Win 95+ \/ Mac OS 8.6-9.2","1.7","A"],
["Gecko","Netscape Browser 8","Win 98SE+","1.7","A"],
["Gecko","Netscape Navigator 9","Win 98+ \/ OSX.2+","1.8","A"],
["Gecko","Mozilla 1.0","Win 95+ \/ OSX.1+","1","A"]
]
}

json消息看起来对我有效,并且jsonlint检查说它也有效。 我花了几天时间寻找解决方案并使用了datatables-debugger(http://debug.datatables.net/equhum) 但我没有想法。 有人可以帮忙吗?

0 个答案:

没有答案