JSON response validated ok, but receive Invalid JSON response.

JSON response validated ok, but receive Invalid JSON response.

aer5aer5 Posts: 3Questions: 1Answers: 0

https://drei.sieben4zehn5.de/minify/serverSideTest/**:
**Debugger code (debug.datatables.net)
: https://debug.datatables.net/anutib
Error messages shown: DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Description of problem:

JSON response validated online ok, but receive Invalid JSON response message, this is my html

<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Title</title>



<link href="../../css/bootstrap-5.0.2-dist/css/bootstrap.css" rel="stylesheet">

<link rel="stylesheet" type="text/css" href="../ext_assets/DataTables/datatables.css"/>


</head>
<body>

arbeitgeber position
arbeitgeber position
$('#example').dataTable( { "processing": true, "serverSide": true, "ajax": { "url": "server_processing.php", "dataType": "jsonp" } } );

</body>
</html>

and this the server-side script:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// DB table to use
$table = 'minify';

// Table's primary key
$primaryKey = 'id';

$columns = array(
array( 'db' => 'arbeitgeber', 'dt' => 0 ),
array( 'db' => 'position', 'dt' => 1 )
);

// SQL server connection information
$sql_details = array(
'user' => 'aer_talea',
'pass' => 'z&5T94jp',
'db' => 'web11573_talea-advisory',
'host' => 'localhost:3306'
);

require( 'ssp.class.php' );

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

thanks in advance
armin

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    Answer ✓

    In your browser use the network inspector to get the JSON response. In Chorme use the Response tab and copy the whole response. Paste it into https://jsonlint.com/ and you will find that it is not valid. The response as this at the end which makes it not valid:

    jQuery33103260158853885291_1645296478322

    Take a look at this JSONP example. The response looks like this:

    jQuery351007647367724333742_1645297334989({
        "draw": 1,
        "recordsTotal": 57,
        "recordsFiltered": 57,
        "data": [
            ["Airi", "Satou", "Accountant", "Tokyo", "28th Nov 08", "$162,700"],
    ....
        ]
    });
    

    I don't use PHP but if you look at the bottom of the script in teh Server-side Script tab you will see some additional code to handle the JSONP request. Looks like you might need to add that to your script.

    Kevin

  • aer5aer5 Posts: 3Questions: 1Answers: 0

    Hi Kevin, thanks, i included the two js-files:
    and the json is valid, but still not working...

  • aer5aer5 Posts: 3Questions: 1Answers: 0

    Solved this make it work:
    $('#example').dataTable( { "processing": true, "serverSide": true, "ajax": { "url": "server_processing.php", "dataType": json" } } );

    dataType json instead of jsonp

    Regards Armin

Sign In or Register to comment.