Error: 'length' is null or not an object aData.length
Error: 'length' is null or not an object aData.length
shooric
Posts: 2Questions: 0Answers: 0
Hi,
i am trying to load the datatable using ajax with a asmx service.
i successful get json back from the server,
but when datatable js calls its internal _fnGetObjectDataFn ,
"data" is null and im assuming it should be an empty array.
at code below
return function (data, type)
{
return data[mSource]; // mSource is aaData
};
the result is my datatable does not bind and a js error of "error: 'length' is null or not an object "
any help would great, been stuck on this for 3 days
so, when the call is made to add data i get
var aData = (oSettings.sAjaxDataProp !== "") ?
_fnGetObjectDataFn(oSettings.sAjaxDataProp)(json) : json;
/* Got the data - add it to the table */
for (i = 0; i < aData.length; i++)
{
_fnAddData(oSettings, aData[i]);
}
this is my service
public string GetEvents123()
{
string a = "{'sEcho': 1,'iTotalRecords': 2,'iTotalDisplayRecords': 2,'aaData':[['01/01/2001','valueone','new york'],['01/02/2002','valueTwo','new jersey']]}";
return a;
}
this my data table
$('#example').dataTable({
'bPaginate': false,
'bInfo': false,
'bFilter': false,
"bProcessing": true,
'bServerSide': false,
'sAjaxSource': 'CalendarServiceView.asmx/GetEvents123',
"fnServerData": function (sUrl, aoData, fnCallback, oSettings)
{
var jsonData = {};
$.each(aoData, function (i, o)
{
jsonData[o.name] = o.value;
});
oSettings.jqXHR = $.ajax({
"url": sUrl,
"data": JSON.stringify(jsonData),
"type": "post",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"cache": false,
"async": true,
"error": function (xhr, status, error)
{
if (error == "parsererror")
oSettings.oApi._fnLog(oSettings, 0, "DataTables warning: JSON data from " + "server could not be parsed. This is caused by a JSON formatting error.");
},
"success": function (json)
{
$(oSettings.oInstance).trigger('xhr', oSettings);
fnCallback(json);
}
});
},
'aoColumns': [{ 'mDataProp': 'date' }, { 'mDataProp': 'event' }, { 'mDataProp': 'location'}]
});
i am trying to load the datatable using ajax with a asmx service.
i successful get json back from the server,
but when datatable js calls its internal _fnGetObjectDataFn ,
"data" is null and im assuming it should be an empty array.
at code below
return function (data, type)
{
return data[mSource]; // mSource is aaData
};
the result is my datatable does not bind and a js error of "error: 'length' is null or not an object "
any help would great, been stuck on this for 3 days
so, when the call is made to add data i get
var aData = (oSettings.sAjaxDataProp !== "") ?
_fnGetObjectDataFn(oSettings.sAjaxDataProp)(json) : json;
/* Got the data - add it to the table */
for (i = 0; i < aData.length; i++)
{
_fnAddData(oSettings, aData[i]);
}
this is my service
public string GetEvents123()
{
string a = "{'sEcho': 1,'iTotalRecords': 2,'iTotalDisplayRecords': 2,'aaData':[['01/01/2001','valueone','new york'],['01/02/2002','valueTwo','new jersey']]}";
return a;
}
this my data table
$('#example').dataTable({
'bPaginate': false,
'bInfo': false,
'bFilter': false,
"bProcessing": true,
'bServerSide': false,
'sAjaxSource': 'CalendarServiceView.asmx/GetEvents123',
"fnServerData": function (sUrl, aoData, fnCallback, oSettings)
{
var jsonData = {};
$.each(aoData, function (i, o)
{
jsonData[o.name] = o.value;
});
oSettings.jqXHR = $.ajax({
"url": sUrl,
"data": JSON.stringify(jsonData),
"type": "post",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"cache": false,
"async": true,
"error": function (xhr, status, error)
{
if (error == "parsererror")
oSettings.oApi._fnLog(oSettings, 0, "DataTables warning: JSON data from " + "server could not be parsed. This is caused by a JSON formatting error.");
},
"success": function (json)
{
$(oSettings.oInstance).trigger('xhr', oSettings);
fnCallback(json);
}
});
},
'aoColumns': [{ 'mDataProp': 'date' }, { 'mDataProp': 'event' }, { 'mDataProp': 'location'}]
});
This discussion has been closed.
Replies
and not json.
Allan