Understanding why JSON response is invalid

Understanding why JSON response is invalid

ashleycashleyc Posts: 4Questions: 2Answers: 0
edited July 2014 in Free community support

Hi, Any advice would be greatly appreciated.. I'm populating a table with the following code:

<?php
$id = $this->session->userdata('dataid');

// DataTables PHP library
include( "DataTables-1.10.0/extensions/Editor-1.3.1/php/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Validate;


// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'jobs' , 'job_id')
    ->fields(
        Field::inst( 'jobs.job_id' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'technicians.technician_id' )
    )
    ->leftJoin( 'technicians', 'technicians.technician_id', '=', 'jobs.technician_id' )
    
    ->where( "job_id","$id","=" )
    ->process( $_POST )
    ->json();

?>

This is the Javascript to go alongside it:

    //Data for iTech
    $( "#dataTables-iTech" ).DataTable( {
        dom: "Trt",
        processing: true,
        serverSide: true,
        ajax: {
          url: "/jobeditor/ajax3",
          type: "POST"
        },
        columns: [              
        { data: "technicians.technician_id" }
        ],
        tableTools: {
            sRowSelect: "os",
            aButtons: [
            ]
        }
    } );

And finally the JSON response that I'm getting:

{"data":[{"DT_RowId":"row_10269","jobs":{"job_id":"10269"},"technicians":{"technician_id":"2"}}]}

So the code does return the data that I want, and using a validator, it says the return is valid. However as soon as it goes to display it in the table I just get an invalid JSON response.

It's really confused me and I can't seem to see my error so any help would be appreciated!

Thanks

(I can't link to the page as it is only local)
Also, if I remove the where clause, it returns all data (as expected) but the response is no longer reported as invalid.

Ashley

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    If you are getting an invalid JSON error message, then the server must be returning something more than the JSON you've posted above, as it is valid. Can you run your table through the debugger and give us the link please: http://debug.datatables.net .

    Allan

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Also, if you aren't using Editor 1.3.2, I would suggest updating!

    Allan

  • ashleycashleyc Posts: 4Questions: 2Answers: 0

    Hi, thanks for your response. The debug tool never completes its cycle so it must be something i've done wrong! I'll post my solution should I find one.

    Ashley

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Bummer about the debugger. I need to look into that.

    The information in tech note 1 shows how you can see the information that is returned by the server.

    Allan

This discussion has been closed.