DataTables not loading any data
DataTables not loading any data
I have this set up which calls a function in a controller. Now I have tried to add type = json but all that does is throw an error saying membernumber is an invalid json primitive. I added the columns part lately hoping that would solve my problem but still nothing shows. I am out of ideas.
var member = $('#MemberNumber').val();
var drive = $('#DriveDate').val();
var table = $('#members').DataTable({
select: {
style: 'single',
},
lengthChange: false,
columns:[
{ "data": "MemberNumber" },
{ "data": "DriveDate" },
{ "data": "ProductType" },
{ "data": "MemberName" },
{ "data": "LibraryStatus" },
{ "data": "BatchStatus" }
],
ajax: {
type: "POST",
url: "/EDP/DocumentCheckInOut/Reload",
data: { "MemberNumber": member, "DriveDate": drive }
//success: function (data) {
// $("#dataDiv").show();
//},
//failure: function()
//{
// alert("Something went wrong!");
//}
},
}
);
Here is my function inside my controller.
[HttpPost]
public JsonResult Reload(string MemberNumber, DateTime? DriveDate)
{
var Repository = new DocumentCheckInOutRepository();
var DocumentCheckInOutVM = new DocumentCheckInOutViewModel();
var Documents = new List<Document>();
Documents = Repository.Retrieve(MemberNumber, DriveDate);
return Json(Documents);
This is a sample row that gets returned
0
Object {MemberNumber="123456", ...}
BatchStatus
""
DriveDate
"/Date(1459400400000)/"
LibraryStatus
"IN"
MemberName
"Test Client"
MemberNumber
"123456"
ProductType
"STC"
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
check your json and post full response here
It looks like the response just wasn't formatted above so it wasn't clear.
Having said that, not that I've added syntax highlighting, it doesn't look like JSON. @monica73174 - can you show us the JSON formatted response please?
Allan
This is what the response looks like. I didn't post the entire response since its 71 records.
{"DriveDate":null,"MemberNumber":null,"draw":1,"recordsTotal":71,"recordsFiltered":71,"data":[{"MemberNumber":"123456,"DriveDate":"\/Date(1459400400000)\/","ProductType":"STC","MemberName":"Test Client 1","LibraryStatus":"IN","BatchStatus":""},{"MemberNumber":"123457","DriveDate":"\/Date(1451541600000)\/","ProductType":"STC","MemberName":"Test Client 2","LibraryStatus":"IN","BatchStatus":""},{"MemberNumber":"123458","DriveDate":"\/Date(1443589200000)\/","ProductType":"QTR","MemberName":"Test Client 3","LibraryStatus":"IN","BatchStatus":""}
It isn't valid JSON - specifically:
Note that it is missing a quote at the end of the number (or possibly it has a quote at the start of the number if you want it to be a number rather than a string).
Use JSONLint to validate JSON data.
Allan