Unable to display data .

Unable to display data .

Abhi RAbhi R Posts: 17Questions: 5Answers: 0
edited June 2017 in Free community support

I have a Json data in this format :-

"[{"MeetingId":269,"MeetingName":"New Meeting 2","HostName":null,"ScheduledDate":"2017-10-06T05:37:00"},{"MeetingId":4305,"MeetingName":"New Meeting","HostName":"Vikash Kumar","ScheduledDate":"2017-06-20T02:35:00"}]"

what is wrong in this ?
Why i am unable to display in table ?
I am getting this error
" DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7 "

This question has an accepted answers - jump to answer

Answers

  • HPBHPB Posts: 73Questions: 2Answers: 18

    Clicking the link from the error message brings you to the specific error page. It starts with:

    When using the ajax option to load data for DataTables, a general error can be triggered if the server responds with anything other than a valid HTTP 2xx response

    This error is not related to json format. It tells you the server is not responding with a HTTP 2xx response.
    It is for you to figure out what exactly the server is responding with.

    If you want us to figure it out, you need to provide a link to the page that is giving you this error or we will never know.

  • Abhi RAbhi R Posts: 17Questions: 5Answers: 0
    edited June 2017

    Hello HPB
    This is in controller

    public string UpcomingMeetings()
    {
    var abc = adminServiceFacade.GetUpcomingMeetingsOfAllUsers();
    var dynamicObj = JsonConvert.DeserializeObject<List<AdminMeetingDTO>>(abc);
    var UpCommingMeetingList =new List<UpcomingMeetingVM>();
    foreach (var item in dynamicObj)
    {
    UpcomingMeetingVM ksj = new UpcomingMeetingVM();
    ksj.HostName = item.HostName;
    ksj.MeetingId = item.MeetingId;
    ksj.MeetingName = item.MeetingName;
    ksj.ScheduledDate = item.Schedule.ScheduledDate;
    UpCommingMeetingList.Add(ksj);
    }
    var r = JsonConvert.SerializeObject(UpCommingMeetingList);
    return r;}

    In script

    function UpcomingMeeting() {
    $.ajax({
    type: 'GET',
    datatype: 'json',
    url: "/Admin/Admin/UpcomingMeetings",
    contentType: "application/json",
    success: function (data) {
    var jsonParse = JSON.parse(data);
    console.log(jsonParse)
    jsonObj = [];
    var rt = JSON.stringify(jsonParse, null, 6);
    for (key in jsonParse) {

                if ([key]==0) {
                    item = 'data:';
                    item = {}
                } else {
                    item = {}
                }       
                    item["MeetingId"] = jsonParse[key].MeetingId;
                    item["MeetingName"] = jsonParse[key].MeetingName;
                    item["HostName"] = jsonParse[key].HostName;
                    item["ScheduledDate"] = jsonParse[key].ScheduledDate;
                    jsonObj.push(item);
                    console.log(jsonObj)
            }
            var j = JSON.stringify(jsonObj)
            console.log(j)
            $('.abcd').DataTable({
                "ajax": j
        },
        error: function (data) {
            $("#upcomingMeeting").hide();
        }
    });
    

    }

  • HPBHPB Posts: 73Questions: 2Answers: 18
    Answer ✓

    Please use Markdown when posting code.

    Right now you're using your own ajax function to retrieve the data and pass it to the ajax option. That is not the way to do it.

    If you want to retrieve and build the data object yourself, you should be passing it to the data option.
    If you want to use the ajax option, you should look at the documentation on how to use it.

  • Abhi RAbhi R Posts: 17Questions: 5Answers: 0

    Thanks :smile:
    I got it :smile:

This discussion has been closed.