Invalid JSON response. Large Data problem!

Invalid JSON response. Large Data problem!

pravindiapravindia Posts: 7Questions: 1Answers: 0

MY code works correctly with small data
nut not working when retrieving large amount of data from table .
Is there any limit in ajax response

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    Answer ✓

    As far as I know there are no limits in place in Datatables. There may be limits in the data size that can be sent form the server or maybe the browser.

    not working when retrieving large amount of data from table .

    What happens?

    What errors do you get?

    Basically you need to follow the path of your data and look at server and client logs for errors to determine the problem. This FAQ provides some guidelines are number of rows and what can be done to improve speed.
    https://datatables.net/faqs/index#speed

    Kevin

  • pravindiapravindia Posts: 7Questions: 1Answers: 0

    Error : DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    var table = $('#example').DataTable({ "stateSave": true, "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ], ajax: { 'url': '<?php echo base_url();?>Admin/view_ajax', 'type': 'POST', 'data': function(data){ var status = $('#filerByStatus').val(); data.filerByStatus = status; } }, });

    and my codeignitor controller is

    ` public function view_ajax(){
    $this->load->model("functions");
    $tablename = $this->session->tablename;
    $fields = $this->db->list_fields($tablename);
    $filerByStatus = $this->input->post('filerByStatus');

        $primaryKey = id';
        $i = 0  ;
    
        $x = array();
    
        foreach($fields as $field){
            array_push( $x , array( 'db' => $field , 'dt' => $i ) );
            $i++;
            // if($i > 7){
            //  break;
            // }
        }
        $columns = $x;
    
        // SQL server connection information
        $sql_details = array(
            'user' => $this->db->username,
            'pass' => $this->db->password,
            'db'   => $this->db->database,
            'host' => $this->db->hostname
        );
    
        require('ssp.class.php');
    
        echo json_encode(
            SSP::simple( $_GET, $sql_details, $tablename, $primaryKey, $columns )
        );
    }`
    

    inthat code if ($i > 7 ) it works correctly ....
    So I think it was with data problem
    I use 2500 rows and 55 columns

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    edited March 2019

    Did you follow the troubleshooting steps provided in link in the error?
    http://datatables.net/tn/1

    Likely you will see an error in your server script indicating the problem.

    I'm not sure what if ($i > 7 ) is doing so won't be much help with your server script. Maybe someone else has an idea.

    Kevin

  • pravindiapravindia Posts: 7Questions: 1Answers: 0
    edited March 2019

    No error message was displayed

    But this code works correctly with small data

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    When you followed the steps in the link http://datatables.net/tn/1 what did you find?

    But this code works correctly with small data

    We need to narrow down which code is not working with the large data set. If Datatables is reporting invalid JSON then it leads me to believe the server is responding with an error instead of JSON data.

    Kevin

  • pravindiapravindia Posts: 7Questions: 1Answers: 0

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    IF there is no response data then that would indicate something is going wrong in your server script.

    Kevin

  • pravindiapravindia Posts: 7Questions: 1Answers: 0

    Malformed UTF-8 characters, possibly incorrectly encoded

    now I;m getting this error

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Malformed UTF-8 characters, possibly incorrectly encoded

    Where are you seeing that error?

    What change did you make to for the error to occur?

    Kevin

  • pravindiapravindia Posts: 7Questions: 1Answers: 0

    ` $x= json_encode(
    SSP::simple( $_GET, $sql_details, $tablename, $primaryKey, $columns ),0,5000000
    );

        if ($x)
        echo $x;
        else{
            echo json_last_error_msg();
        }`
    
  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Is your DB set for UTF-8?

    My recommendation is to search Stackoverflow for the error. Seems there are many discussion about this error. Maybe you can find a solution based on your DB and environment.

    Kevin

This discussion has been closed.