Error: 'length' is null or not an object aData.length

Error: 'length' is null or not an object aData.length

shooricshooric Posts: 2Questions: 0Answers: 0
edited November 2012 in DataTables 1.9
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'}]
});

Replies

  • shooricshooric Posts: 2Questions: 0Answers: 0
    well, shortly after i figuared out that i need to be passing a object with a property aaData that is an array;
    and not json.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited November 2012
    You can use sAjaxDataProp and set it to an empty string to use an array of objects / arrays.

    Allan
This discussion has been closed.