0

I want to use the jquery liberary datatables with jsp and mysql. I have try the jsp-based serverside processing example (https://datatables.net/development/server-side/jsp) and get the error message:

DataTables warning (table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.

The example comprises a mysql database and the source on a .jsp that should run on the serverside. The clientside that should invoke the serverside .jsp to give a json message with content of the databases was not included, so I made some little adjustments to the clientside of a simular .php example.

<!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>

The error indicates, that there is as problem with json parsing. Thus I used firebug to have a look at the json response form the server. Here the result:

{"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"]
]
}

The json message looks valid to me and a check with jsonlint say also it`s valid. I have spent days with searching for a solution and used also the datatables-debugger (http://debug.datatables.net/equhum) but I have no idear. Could somebody help?

4
  • your question is too vague, where is the error actually happening? can you reduce the scope and repeat the error in a simpler scenario? Commented Feb 18, 2014 at 19:13
  • I have no clue how to make this scenario more simple. I guess one page one the client side, one page (jsp) on the server side and one database seens to be the most simple setting for this serverside processing. Allso the datatables website has deliverd this example. Commented Feb 18, 2014 at 19:36
  • The error seens to occur after the server side has answered and the datatables skript try to parsing the json message. But why is the question... Commented Feb 18, 2014 at 19:45
  • who generate the json? I would you to use an api like jsonparser to try to parse this json and see if it is well formatted Commented Feb 18, 2014 at 20:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.