Invalid JSON response

Invalid JSON response

th3t1ckth3t1ck Posts: 200Questions: 33Answers: 1

So I'm having some difficulty getting a server side script to work. I ran the following JSON data through JSON Lint and it tells me it is valid JSON.

["7","Border Division","6","Southern Division","5","Central Division"]

My Script creates an array with an id and division name. I read the information at and followed the directions.

My html looks like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<?php include('css_js.html'); ?>
<title>Page title</title>
$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": 'ajax_test.php',
                        columns: [
        { data: 'id' },
        { data: 'division' },
    } );
} );

<table id="example" class="display" style="width:100%">


And my ajax script looks like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

$result= $dbConn->query("SELECT, lk_divisions.division FROM lk_divisions, eow WHERE");
$row_cnt = $result->num_rows;

 while($row=$result->fetch_assoc()) {
     if($x === 1) {
        $myArray=array($divisionId, $divisionName);
                array_push($myArray, $divisionId, $divisionName);

$myJSON = json_encode($myArray);

echo $myJSON;


What am I doing wrong?

This question has an accepted answers - jump to answer


  • kthorngrenkthorngren Posts: 11,025Questions: 25Answers: 2,524
    Answer ✓

    ["7","Border Division","6","Southern Division","5","Central Division"]

    Is this the full JSON response seen in the browser's developer tools?

    It may be valid per but it's not a structure that Datatables support. Datatables expects the ajax response to be an array of objects or an array of arrays. This is discussed here:

    By default Datatables expects the row data to be in a data object. You can tell Datatables to look elsewhere in the response using the ajax.dataSrc option. This is discussed here:

    This isn't causing the invalid JSON response error but you have defined but are receiving the data in an array. This is a mismatch which will likely result in the Requested unknown parameter once you get past the invalid JSON error. When using arrays you will want something more like this example:


  • th3t1ckth3t1ck Posts: 200Questions: 33Answers: 1

    Yes that is the response I get in the developer tools. I'll do some reading in the links you provided to see if I can get this working. Thank you.

Sign In or Register to comment.