How can I debug "Invalid JSON response"

How can I debug "Invalid JSON response"

geist0geist0 Posts: 10Questions: 2Answers: 0

Hello!
I get an << Invalid JSON response>> error but have no response from server - debuger shows empty response.

Regards,
Rafal

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Did you follow the link that the error gives: http://datatables.net/tn/1 ? It shows how you can debug that issue.

    Allan

  • geist0geist0 Posts: 10Questions: 2Answers: 0
    edited January 2016

    Hello Allan.
    Thank you for you fast response :)
    Answering you question: yes, I am quite familiar with ff debuger. The problem is that "Response" tab shows empty response (in Firebug there is even no Response Tab). Looks like server send nothing.
    This problem is probably connected with environment I am working. I have no problem working in a local network but opening page from server via vpn error occurs.
    It occurs on table/editor posting via object-style php; two another tables working with my own "flat" scripts work well.

    Rafal

  • geist0geist0 Posts: 10Questions: 2Answers: 0
    edited January 2016

    Here are queries, I got from editor_sql:

    SELECT MARKTWO_Task.id as 'MARKTWO_Task.id',
    MARKTWO_Task.id as 'MARKTWO_Task.id',
    MARKTWO_Task.name as 'MARKTWO_Task.name',
    MARKTWO_TaskType.name as 'MARKTWO_TaskType.name',
    MARKTWO_Task.type_id as 'MARKTWO_Task.type_id',
    MARKTWO_Task.appear_date as 'MARKTWO_Task.appear_date',
    MARKTWO_Task.prev_task_id as 'MARKTWO_Task.prev_task_id',
    MARKTWO_Task.description as 'MARKTWO_Task.description'
    FROM MARKTWO_Task
    LEFT JOIN MARKTWO_TaskType ON MARKTWO_TaskType.id = MARKTWO_Task.type_id
    SELECT DISTINCT id as 'id', name as 'name' FROM MARKTWO_TaskType
    SELECT MARKTWO_Task.id as dteditor_pkey, MARKTWO_TaskOwner_MAP.owner_id as owner_id, MARKTWO_TaskOwner_MAP.task_id as task_id FROM MARKTWO_Task as MARKTWO_Task JOIN MARKTWO_TaskOwner_MAP ON MARKTWO_TaskOwner_MAP.task_id = MARKTWO_Task.id

    and ajax url source:

    Editor::inst( $db, 'MARKTWO_Task' ) ->fields( Field::inst('MARKTWO_Task.id as id'), Field::inst('MARKTWO_Task.name as name') ->validator('Validate::notEmpty', array("message" => "Nazwa nie może być pusta")) ->validator('Validate::unique', array("message" => "Lista o takiej nazwie już istnieje")), Field::inst('MARKTWO_TaskType.name as type'), Field::inst('MARKTWO_Task.type_id as type_id') ->options('MARKTWO_TaskType', 'id', 'name'), Field::inst('MARKTWO_Task.appear_date as date'), Field::inst('MARKTWO_Task.prev_task_id as prev_task_id'), Field::inst('MARKTWO_Task.description as description') ) ->leftjoin('MARKTWO_TaskType', 'MARKTWO_TaskType.id', '=', 'MARKTWO_Task.type_id') ->join( Mjoin::inst('MARKTWO_TaskOwner_MAP') ->name('Owners') ->link('MARKTWO_Task.id', 'MARKTWO_TaskOwner_MAP.task_id') ->fields( Field::inst('owner_id'), Field::inst('task_id') ) ) ->process($_POST) ->json();

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Looks like server send nothing.

    Sounds like a server error in that case. Have you checked your server's error logs to see if there is any information shown there?

    Allan

  • geist0geist0 Posts: 10Questions: 2Answers: 0

    No, not yet but I will; it's a long time process as I need to ask admin to send me logs ;)
    Thanks,
    Rafal

  • geist0geist0 Posts: 10Questions: 2Answers: 0
    edited January 2016

    Dear Allan,
    I have checked server error log and it doesn't return any error regarding mentioned script. Finally I made such test:

    I addedd some echo on the begining with Polish diacritics to ensure that is not a coding problem (isn't it?):

    <?php
    echo("dópą");
    include("DataTables.php");
     
    use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;
    
    $db->sql("SET character_set_client=utf8");
    $db->sql("SET character_set_connection=utf8");
    $db->sql("SET character_set_results=utf8");
     
    Editor::inst( $db, 'MARKTWO_User' )
        ->fields(
            Field::inst( 'id' ),
            Field::inst( 'name' ),
            Field::inst( 'login' ),
            Field::inst( 'email' ),
            Field::inst( 'admin' ),
            Field::inst( 'active' )
                ->setFormatter( function ( $val, $data, $opts ) {
                    return ! $val ? 0 : 1;
                } )
        )
        ->process( $_POST )
        ->json();
    

    And responses are:

    1. From local server:
      dópą{"data":[{"DT_RowId":"row_1","id":"1","name":"Super ...

    2. From outside server:
      dópą

    Have you any idea, where do I need to look?

    Kind regards,
    Rafal

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    So you have this working on one server and not the other? What is the difference between the servers? What version of PHP are they running for example.

    Allan

  • geist0geist0 Posts: 10Questions: 2Answers: 0

    First one: Synology DSM 5.2, Apache 2.2, PHP 5.5 - working properly
    Second one: FreeBSD, Apache 2, PHP 5.6 - not working

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    Editor should certainly work on a PHP 5.6 server, so I'm afraid I don't have an immediate answer for you. All I can really suggest, in the absence of other information, is to enable all debugging options in your PHP and check the error log.

    It might be worth putting the echo("dópą"); after the use statement. I'm surprised your PHP isn't giving an error about that at least.

    Allan

  • geist0geist0 Posts: 10Questions: 2Answers: 0
    edited January 2016

    Allan,
    I have put echo just after the new statement and response is empty:

    Status code: 200
    Response:
    

    Rafal

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin
    Answer ✓

    Do you mean the use statement?

    What you are seeing very much suggests that there is an error in the server configuration - particularly if it works for you on a different server.

    Have you enabled all possible debugging in PHP? It really should show an error if something is going wrong.

    Allan

  • geist0geist0 Posts: 10Questions: 2Answers: 0
    edited January 2016

    Oh, pardon! Yes after use statement.
    Allan, many thanks for you support and help; finally I have found the problem and it was an error in completelly different script - undefined variable. I don't understant this behaviour but removeing this - seemingly unrelated - error helped!

    Thank you for such fantastic library :)

    Regards,
    Rafal

This discussion has been closed.