datatable ajax source

datatable ajax source

lakshman553lakshman553 Posts: 3Questions: 2Answers: 0

hi, i get the invalid json error. i have tried JSON parser and couple of other parser, all of them shows my json is valid.

somehow datatable shows wrong format error.

please help

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    Per the forum rules, please link to the page so we can debug it.

    Allan

  • lakshman553lakshman553 Posts: 3Questions: 2Answers: 0

    this is my json file

    {
        "records": [
            {
                "MarkTime": "2015-07-22T23:00:43.08",
                "latitude": 130.72612,
                "longitude": 76.70462,
                "markCount": null,
                "strMarkTime": "23:00",
                "imageURL": "2015/07/22/"
            },
            {
                "MarkTime": "2015-07-22T23:01:05.49",
                "latitude": 30.72612,
                "longitude": 76.70462,
                "markCount": null,
                "strMarkTime": "23:01",
                "imageURL": "2015/07/22/"
            },
            {
                "MarkTime": "2015-07-22T23:13:28.08",
                "latitude": 30.726123,
                "longitude": 76.7046322,
                "markCount": null,
                "strMarkTime": "23:13",
                "imageURL": "2015/07/22/"
            },
            {
                "MarkTime": "2015-07-22T23:15:02.89",
                "latitude": 30.726123,
                "longitude": 76.7046322,
                "markCount": null,
                "strMarkTime": "23:15",
                "imageURL": "2015/07/22/"
            }
        ]
    }
    

    i have imported

      <script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
         <script type="text/javascript" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
        <link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css"/>
    

    my javascript is

     $(document).ready(function () {
    
            $('#example1').dataTable({
                "ajax": 'json1.json'
            });
            });
    

    i get the error

    Uncaught TypeError: Cannot read property 'length' of undefined
    
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Use ajax.dataSrc to tell DataTables if you want it to read data from somewhere other than the default data property in the object. In this case you would use dataSrc: 'records' - otherwise DataTables won't know that is where you keep your data.

    Allan

This discussion has been closed.