DataTables warning: table id=datatable-fixed-header1 - Invalid JSON response.

DataTables warning: table id=datatable-fixed-header1 - Invalid JSON response.

UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

I am using jQuery DataTables in laravel vuejs and I applied serverside pagination to load the first page only with 5 records when I try to search a record in all table it does not work but the search only works in the 5 loaded data I search in the web and I found that I should set serverSide: true, but when I set that it throws the below error.

DataTables warning: table id=datatable-fixed-header1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Jquery datatable code is below

$(document).ready(function() {
var tables = $("#datatable-fixed-header1").DataTable({
retrieve: true,
processing: true,
serverSide: true,
// paging: false,
dom: "t",
paging: true,

// scrollX: true,
lengthChange: true,
searching: true,
ordering: true

});
});
$(document).on("keyup", "#bookSearch", function() {
var tables = $("#datatable-fixed-header1").DataTable({
retrieve: true,
processing: true,
serverSide: true,

// paging: false,
dom: "t",
paging: true,
// scrollX: true,
lengthChange: true,
searching: true,
ordering: true

});
tables.search($(this).val()).draw();
});

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Did you follow the instructions at the link provided in the error?

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

    Let us know what you find.

    Kevin

  • UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

    in the console, it gives me this error
    app.js:43082 Uncaught TypeError: Cannot set property 'data' of null

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited March 2020

    What do you find when you follow the troubleshooting steps in the link?
    http://datatables.net/tn/1

    Kevin

  • UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

    the table is loaded successfully but When I try to search for data on the second page after pagination it does not work and in the console, it gives me this error
    Uncaught TypeError: Cannot set property 'data' of null

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

    why search is not working with serverside pagination ?

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    The server script is responsible for searching using this protocol:
    https://datatables.net/manual/server-side

    Are you using a Datatables provided server script?

    Does your script support the server side protocol?

    You can use the steps in the technote link of the error to see what the server response is.

    If this doesn't help then as Colin mentioned we will need to have a link to your page to help debug.

    Kevin

  • UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

    I could not post the link because I am developing the application in the local system so here are the attached pictures



  • UsmanBasharmalUsmanBasharmal Posts: 14Questions: 3Answers: 0

    one more picture

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    The problem is with your server script not returning the correct data. You will need to look at your server script for errors. You didn't answer any of my questions in the last post regarding your server script.

    Kevin

This discussion has been closed.