“Uncaught TypeError: Cannot use 'in' operator to search for 'length' in ” triggered by Datatables plugin and jQuery 1.11.3

后端 未结 8 1184
北恋
北恋 2021-02-12 13:17

I\'m using the jQuery Datatables plugin to enable pagination, sorting and searching with my tables. The elements are showing up but not working, and the pagination only sometime

8条回答
  •  佛祖请我去吃肉
    2021-02-12 13:37

    With DataTables and calling a PHP-script with AJAX, be aware that you just must echo your array at the end. There is no need of encoding it first to a JSON object with json_encode.

    So

    header('Content-type:application/json;charset=utf-8'); 
    echo $myArray // This will do. Do not use echo json_encode($myArray);
    exit();
    

    Otherwise you might end up with the dreadful error

    Uncaught TypeError: Cannot use 'in' operator to search for 'length' in

    or this one

    Uncaught TypeError: Cannot read property 'length' of undefined

提交回复
热议问题