I am getting "No data available in table" even though my handler is returning valid json (I've test)

I am getting "No data available in table" even though my handler is returning valid json (I've test)

sfureysfurey Posts: 2Questions: 2Answers: 0

My handler code is:

        List<employee> li = new List<employee>();
        employee e = new employee();
        e.Name = "Tiger Nixon";
        e.Position = "System Architect";
        e.Office = "Edinburgh";
        e.Extn = "5421";
        e.StartDate = "today";
        e.Salary = "lots";
        li.Add(e);
        var anon = new { data = e };
        var jsonSerialiser = new System.Web.Script.Serialization.JavaScriptSerializer();
        var isJSON = jsonSerialiser.Serialize(anon);
        context.Response.ContentType = "application/json";
        context.Response.Write(isJSON);

The JSON being returned by my Handler (working in a .net enviroment) is:

{"data":{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","StartDate":"today","Salary":"lots"}}

My javascript is :

$('#example').DataTable({
    "processing": true,
    "serverSide": false,
    "ajax": 'http://localhost/3d/Handler2.ashx',
    "columns": [
        { "data": "Name" },
        { "data": "Position" },
        { "data": "Office" },
        { "data": "Extn" },
        { "data": "StartDate" },
        { "data": "Salary" }
    ]
});

Does anybody have an idea of what I am doing wrong?? I'm getting the "No Data Available in table" even though tis appears to be valid JSON I've been pulling my hair on this for two fulldays now :(

Thanks in advance for any help you can give me!!!

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015 Answer ✓

    Well acording to the json you posted, you have an object inaide an object, the data object needs to contain arrays, not objects, then objects (row data) inside that array

    Should be

    {"data":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","StartDate":"today","Salary":"lots"}]}
    
This discussion has been closed.