DataTable Ajax with Remote Data Source & JSON
DataTable Ajax with Remote Data Source & JSON
OzkarServices
Posts: 4Questions: 0Answers: 0
Guys
Im trying to load data from a Remote Data Source and it keeps failing. Below is my Web Method developed in VB.NET.
[code]
_
Public Shared Function Users() As String
Dim TheFitFemContext As EntitiesContext = New EntitiesContext
Dim Results = (From U In EntitiesContext.Users
Select New With {U.UserID})
Dim serializer As New JavaScriptSerializer()
Dim json As String = serializer.Serialize(Results)
Return json
End Function
[/code]
Here's my jQuery Code
[code]
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": ApplicationPath + "/Administrator/Users.aspx/Users",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": '{}',
"success": function (data)
{
fnCallback(data.d);
}
});
}
})
[/code]
When I run the code and I get the following as my Results
[code]
{"d":"[{\"UserID\":\"451\",\"Name\":\"John Doe\",\"Address\":\"123 Test Ave, DK, 11234\",\"Date_Created\":\"\\/Date(1327039200000)\\/\",\"Status\":\"Not Active\",\"IsLockedOut\":\"Not Locked Out\",\"Type\":\"Trial\",\"Email\":\"UserName@DomainName.com\",\"ResetPassword\":\"*\"}]"}
[/code]
and my table does not populate instead I get this error
[quote]
Error: Unable to get value of the property 'length': object is null or undefined
[/quote]
Im trying to load data from a Remote Data Source and it keeps failing. Below is my Web Method developed in VB.NET.
[code]
_
Public Shared Function Users() As String
Dim TheFitFemContext As EntitiesContext = New EntitiesContext
Dim Results = (From U In EntitiesContext.Users
Select New With {U.UserID})
Dim serializer As New JavaScriptSerializer()
Dim json As String = serializer.Serialize(Results)
Return json
End Function
[/code]
Here's my jQuery Code
[code]
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": ApplicationPath + "/Administrator/Users.aspx/Users",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": '{}',
"success": function (data)
{
fnCallback(data.d);
}
});
}
})
[/code]
When I run the code and I get the following as my Results
[code]
{"d":"[{\"UserID\":\"451\",\"Name\":\"John Doe\",\"Address\":\"123 Test Ave, DK, 11234\",\"Date_Created\":\"\\/Date(1327039200000)\\/\",\"Status\":\"Not Active\",\"IsLockedOut\":\"Not Locked Out\",\"Type\":\"Trial\",\"Email\":\"UserName@DomainName.com\",\"ResetPassword\":\"*\"}]"}
[/code]
and my table does not populate instead I get this error
[quote]
Error: Unable to get value of the property 'length': object is null or undefined
[/quote]
This discussion has been closed.
Replies
[code]
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": ApplicationPath + "/Administrator/Users.aspx/Users",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"type": "POST",
"url": sSource,
"data": '{}',
"success": function (data) {
var s = $.parseJSON(data.d);
fnCallback(s);
}
});
}
})
[/code]
[code]
{"d":"[{\"UserID\":\"451\",\"Name\":\"John Doe\",\"Address\":\"123 Test Ave, DK, 11234\",\"Date_Created\":\"\\/Date(1327039200000)\\/\",\"Status\":\"Not Active\",\"IsLockedOut\":\"Not Locked Out\",\"Type\":\"Trial\",\"Email\":\"UserName@DomainName.com\",\"ResetPassword\":\"*\"}]"}
[/code]
I'd suggest you probably don't want server-side processing... http://datatables.net/usage/
Allan
Allan