Invalid Json

Invalid Json

Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

All of a sudden all of our Editor tables stopped working. I get the invalid JSON message. I see an ajax response with the data we need but when I run it through lint is says:

Error: Parse error on line 1:
data[{ …}, { …}, {
^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

Any help would be appreciated.
Janet

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited August 2021

    data[{ …}, { …}, {

    Looks like its missing a : between data and the array. Also, since its an object it should be inside a set of braces {}. Should look something like this:

    { 
      data: [{ …}, { …}, { .... }]
    }
    

    Take a look at the example client/server data exchanges.

    Kevin

  • Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

    Okay but why is Editor doing it and how do I fix it?

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Is the Editor server code you are using provided by Datatables or your own code?

    Can you provide a link to the developers so the can take a look?

    Kevin

  • Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

    I deleted anything on the page I thought might be causing a conflict and now the console says:

    <br />
    <b>Deprecated</b>: define(): Declaration of case-insensitive constants is deprecated in <b>/var/www/vhosts/dev-roe-vti.org/httpdocs/editor/php/DataTables.php</b>

    and then the json starts. Here is the link:
    https://dev-roe-vti.org/iodashboard/schoolinfo.php

    I appreciate you looking into it

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited August 2021

    Looks like the problem happens when initializing the Datatable not when using the Editor. You Datatables uses this to load the data:

    ```js
    $('#cif').DataTable( {
    //sDom: "Bfrtipl",
    "sDom": '<"top"<"actions">Bfl<"clear">><"clear">rtpi<"bottom">',
    ajax: {
    url: "../editor/php/cif_schoolinfo_processing.php",
    type: 'POST'
    },

    ````

    Is cif_schoolinfo_processing.php a Datatables provided script or your own? That is where the debugging will need to take place to determine why the response contains:

    <br />
    <b>Deprecated</b>: define(): Declaration of case-insensitive constants is deprecated in <b>/var/www/vhosts/dev-roe-vti.org/httpdocs/editor/php/DataTables.php</b> on line <b>13</b><br />

    Maybe a search of https://stackoverflow.com/ will help resolve the error Declaration of case-insensitive constants is deprecated. See if this SO thread helps.

    Kevin

  • Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

    It is a datatables provide script that was included in Editor that we just clone. It is super simple:

    <?php
    session_start();
    
    // DataTables PHP library
    include( "DataTables.php");
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    Editor::inst( $db, 'cif.schoolinfo', 'id' )
        ->field(
            Field::inst( 'cif.schoolinfo.id' ),
            Field::inst( 'cif.schoolinfo.schoolboard' ),
            Field::inst( 'cif.schoolinfo.fullschoolname' ),
            Field::inst( 'cif.schoolinfo.streetnumber' ),
            Field::inst( 'cif.schoolinfo.streetname' ),
            Field::inst( 'cif.schoolinfo.unitnumber' ),
            Field::inst( 'cif.schoolinfo.city' ),
            Field::inst( 'cif.schoolinfo.province' ),
            Field::inst( 'cif.schoolinfo.postalcode' ),
            Field::inst( 'cif.schoolinfo.principalfirstname' ),
            Field::inst( 'cif.schoolinfo.principallastname' ),
            Field::inst( 'cif.schoolinfo.phone' ),
            Field::inst( 'cif.schoolinfo.fax' )
        
        
        )
        
    
        ->process($_POST)
        ->json();
    
  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    I don't see a call to define() in that code. Do you have a call to define() in your DataTables.php script? And does it have a third parameter set to true?

    Kevin

  • Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

    The call to define is in Datatables.php and I changed
    define("DATATABLES", true, true);
    to
    define("DATATABLES", true, false);
    and it fixed it.

  • Twiggy21Twiggy21 Posts: 16Questions: 6Answers: 0

    Thank you for your help

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sounds like you might have an old version of the Editor PHP libraries? We no longer use the third parameter for define.

    Allan

Sign In or Register to comment.