Ajax generating Cannot read property 'error' of undefined

Ajax generating Cannot read property 'error' of undefined

lecleardlecleard Posts: 9Questions: 2Answers: 1

This would lead me to believe that data is null. However, the datatable is populating with the data returned from my rest call. I'm not sure what I'm missing. It works without the error when I use a text file. The data in the text file is the same as that being returned from the server as I cut and pasted from the server response to test. This is how I'm building my datatable with the ajax params:

var table = $('#location').DataTable( {
      'bServerSide': true,
      'sAjaxDataProp': "locBase",
      "sAjaxSource": "http://localhost:8080/rest/heldlocs",
      'aoColumns': [
        { "mData": "locationCode" },
        { "mData": "companyName" },
        { "mData": "companyContactName" },
        { "mData": "tcpServerURL" },
        { "mData": "operatorNotes" }
      ]
    });

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    Posting the JSON returned from the server is a place to start. Maybe even getting debugger output.

    Kevin

  • allanallan Posts: 63,219Questions: 1Answers: 10,416 Site admin
    Answer ✓

    Note that using the legacy sAjaxSource option will drop DataTables into its legacy mode if you are using server-side processing. ajax is the preferred option now.

    Is you server-side script written for legacy or current (see the manual for details)?

    Allan

  • lecleardlecleard Posts: 9Questions: 2Answers: 1

    Thanks Allan, the manual helped. I think I know what my issue is now.

    var table = $('#location').DataTable( {
          "serverSide": true,
          "ajax": {
            "url": "http://localhost:8080/rest/heldlocs",
            //"url": "/src/data/heldlocs",
            "dataSrc": "locBase"
          },
          "columns": [
            { "data": "locationCode" },
            { "data": "companyName" },
            { "data": "companyContactName" },
            { "data": "tcpServerURL" },
            { "data": "operatorNotes" }
          ]
        });
    

    I updated the code to the above. It works with "/src/data/heldlocs" and fails with the server call. That being said, my JSON returned from the server does not contain draw, recordsTotal, or recordsFiltered parameters. I'll add those to my response and I imagine this issue will go away.

    Thanks again.

  • allanallan Posts: 63,219Questions: 1Answers: 10,416 Site admin

    Do you actually need server-side processing? If you have less that 50'000 rows in the table, just remove the serverSide option.

    Allan

This discussion has been closed.