What is wong with this Code?

What is wong with this Code?

rishabhanandrishabhanand Posts: 2Questions: 1Answers: 0
edited June 2019 in Free community support

Getting error of

Uncaught TypeError: Cannot read property 'length' of undefined
    at wb (jquery.dataTables.min.js:40)
    at jquery.dataTables.min.js:37
    at i (jquery.dataTables.min.js:35)
    at Object.success (jquery.dataTables.min.js:36)
    at c (jquery-3.4.0.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-3.4.0.min.js:2)
    at l (jquery-3.4.0.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery-3.4.0.min.js:2)

Code Below

$(document).ready(function() {

     let table = $('#usertable').DataTable({
      "processing": true,
      "serverSide": true,
      "ajax": {
        "url": "/userTable/usersTable",
        "type": "POST",
        "data": function ( d )
              {
                  d.role   = $('#rolebtn').val();
                  d.status = $('#statusbtn').val();
              }, 
      },
      "columns": [
      {
        "data" : "email"
      },
      {
        "data" : "phoneno"
      },
      {
        "data" : "city"
      },
      {
        "data" : "status"
      },
      {
        "data" : "role"
      },
      {
        "data" : null,
        "orderable" : "false"
      },
      ],
      "columnDefs": [{
                "targets": -1,

                "render": function (data, type, row, meta) {
return '<button></button>';
                }
            }],

    });

I am Not able to access 'req.body.search.value' from sever Side In Node JS ?

Answers

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    Cannot read property 'length' of undefined

    There are many threads with this question, like this:
    https://datatables.net/forums/discussion/comment/152611/#Comment_152611

    It could be something with the Ajax response. Use the browser's developer tools to look at the ajax response. This doc explains what the expected structure is in the response. Post the response in the thread.

    Also it would help to use Markdown formatting to format your code. Use the triple back ticks.

    Kevin

  • rishabhanandrishabhanand Posts: 2Questions: 1Answers: 0
    edited June 2019

    How to access search value In node JS, whenever i use req.body.search.value it shows error? How to solve?
    It shows someTimes : "TypeError: Cannot read property 'value' of undefined".
    Data recived from dataTable

    [Object: null prototype] {
    draw: '1',
    'columns[0][data]': 'email',
    'columns[0][name]': '',
    'columns[0][searchable]': 'true',
    'columns[0][orderable]': 'true',
    'columns[0][search][value]': '',
    'columns[0][search][regex]': 'false',
    'columns[1][data]': 'phoneno',
    'columns[1][name]': '',
    'columns[1][searchable]': 'true',
    'columns[1][orderable]': 'true',
    'columns[1][search][value]': '',
    'columns[1][search][regex]': 'false',
    'columns[2][data]': 'city',
    'columns[2][name]': '',
    'columns[2][searchable]': 'true',
    'columns[2][orderable]': 'true',
    'columns[2][search][value]': '',
    'columns[2][search][regex]': 'false',
    'columns[3][data]': 'status',
    'columns[3][name]': '',
    'columns[3][searchable]': 'true',
    'columns[3][orderable]': 'true',
    'columns[3][search][value]': '',
    'columns[3][search][regex]': 'false',
    'columns[4][data]': 'role',
    'columns[4][name]': '',
    'columns[4][searchable]': 'true',
    'columns[4][orderable]': 'true',
    'columns[4][search][value]': '',
    'columns[4][search][regex]': 'false',
    'columns[5][data]': '',
    'columns[5][name]': '',
    'columns[5][searchable]': 'true',
    'columns[5][orderable]': 'false',
    'columns[5][search][value]': '',
    'columns[5][search][regex]': 'false',
    'order[0][column]': '0',
    'order[0][dir]': 'asc',
    start: '0',
    length: '10',
    'search[value]': '',
    'search[regex]': 'false',
    role: 'All',
    status: 'All' }

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955

    What you show is the data that is sent to the server. What is the response data?

    How to access search value In node JS, whenever i use req.body.search.value it shows error?

    Not sure how to access it. What is the error it generates?

    Kevin

This discussion has been closed.