Invalid JSON response

Invalid JSON response

GargiucnGargiucn Posts: 104Questions: 29Answers: 0

I'm going crazy for an "Invalid JSON response" error that I can not understand...
Chrome debug->network shows this message:

Notice: Undefined index: order in C:\inetpub\wwwroot\test\php\Editor.php on line 1567
{"data":[{"DT_RowId":"row_1","visite":{"vis_user":"4","vis_data":"10-11-2018","vis_cli":"5","vis_esito":"0"},"utenti":{"ute_user":"Admintest"},"clienti":{"cli_ragsoc":"Abcdefg"}}],"options":[],"files":[],"draw":1,"recordsTotal":"1","recordsFiltered":"1"}

$(document).ready(function() {
    var table = $('#visite-all-home').DataTable( {
        responsive: true,
        processing: true,
        serverSide: true,
        ajax: {
            url: "php/visite-all-home.php",
            type: "POST"
        },  
        columns: [
            {data: "visite.vis_data"},
            {data: "utenti.ute_user"},
            {data: "clienti.cli_ragsoc"},   
            {data: "visite.vis_esito", 
                render: function ( val, type, row ) {
                    return val == 0 ? "Negativo" : "Positivo";
                                }
            }
        ],
        select: false,
        searching: false, 
        ordering: false,
        paging: false,
        info: false,
        language: {
            emptyTable:     "Nessun dato presente nella tabella",
            zeroRecords:    "Nessun dato presente nella tabella"
        }
    } );
} );

include( "DataTables.php" );

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

Editor::inst( $db, 'visite', 'vis_id' )
    ->fields(
        Field::inst( 'visite.vis_user' ),
        Field::inst( 'utenti.ute_user' ),
        Field::inst( 'visite.vis_data' )
            ->getFormatter( Format::dateSqlToFormat( 'd-m-Y' ) ),

        Field::inst( 'visite.vis_cli' ),    
        Field::inst( 'clienti.cli_ragsoc' ),
        Field::inst( 'visite.vis_esito' )
    )
    ->leftJoin( 'utenti', 'ute_id', '=', 'visite.vis_user' )
    ->leftJoin( 'clienti', 'cli_id', '=', 'visite.vis_cli' )
    ->process( $_POST )
    ->json();
?>

TABLE `visite`
`vis_id` int(10) UNSIGNED AUTOINCREMENT NOT NULL,
`vis_user` smallint(5) NOT NULL,
`vis_cli` mediumint(8) NOT NULL,
`vis_data` datetime DEFAULT NULL,
`vis_esito` tinyint(3) DEFAULT '0' COMMENT '0=esito negativo, 1=esito positivo, 2=firmato contratto'

INSERT INTO `visite` (`vis_id`, `vis_user`, `vis_cli`, `vis_data`, `vis_esito`) VALUES
(1, 4, 5, '2018-11-10 00:00:00', 0);

PRIMARY KEY (`vis_id`),
KEY `visit_cli` (`vis_cli`),
KEY `visit_user` (`vis_user`),
KEY `visit_date` (`vis_data`),

It seems like a very simple program ... I'm probably tired and I can not find a trivial mistake, but I'm frustrated ...
Thanks to those who help me understand,

Giuseppe

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    You're not initialising your Editor in your js.
    Look at the basic example:
    https://editor.datatables.net/examples/simple/simple.html

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    I do not have editor initialized in the js file because I do not use editor but only the view.
    I have many other pages "apparently" configured in the same way, which is why I got lost ...

    Thank you,
    Giuseppe

  • kthorngrenkthorngren Posts: 20,322Questions: 26Answers: 4,774

    The JSON above looks ok. Can you provide a link to your page?

    If not please use the Datatables Debugger and provide the resulting link or code.
    https://datatables.net/manual/tech-notes/10#DataTables-debugger

    Kevin

  • GargiucnGargiucn Posts: 104Questions: 29Answers: 0

    I solved the problem but I need someone to explain it to me!!!
    removing:

     ordering: false,
    

    everything works! (but the arrows for sorting remain visible, also adding:

     orderable:false,
    

    for each field).

    The problem only occurs if there are some leftjoins with other tables.
    If I only display fields from the same table, everything works properly.
    For this reason I wrote to have other tables "apparently" equal but fully functional.
    I go back to work after losing a lot of time ...

    Giuseppe

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Thank you - that is indeed an error in the Editor PHP libraries when using server-side processing. They were not coping with the use of ordering being disabled.

    I've committed a fix for that and it will be in Editor 1.8.2.

    Regards,
    Allan

This discussion has been closed.