Server-side processing: aData is undefined

Server-side processing: aData is undefined

tarayislandgirltarayislandgirl Posts: 2Questions: 0Answers: 0
edited August 2013 in General
Hi there

I'm really struggling with something. I've set up server-side processing using C# web method. Prior to using server side processing, I tried populating the grid by using ajax in a simlar fashion and it worked, however, using server side processing, it's now telling me that aData is undefined in jquery.datatables.js at the line

var aData = _fnGetObjectDataFn(oSettings.sAjaxDataProp)(json);
for (var i = 0, iLen = aData.length; i < iLen; i++) {

My table is defined as such




Filename
File Date
MPT ID
Status
Uploaded By
Number of Payments in File
Authorised
Authorised By
Settlement Received
Payment Sent
Number of Payments Needing Attention





Refreshing data. Please wait...




My initialisation of the datatable is:

jQuery(document).ready(function () {
var rootpath = ('<%= ResolveClientUrl("~/WebServices/UploadedFilesService.asmx/") %>');
var dataObj = { internalAccountId: '<%= CurrentClientId %>', isForHomePage: '<%= OnHomePage %>' };

jQuery('#uploadedFiles').dataTable({


"bAutoWidth": false,
"bProcessing": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bDeferRender": true,
"bFilter": false,
"bInfo": false,

"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": rootpath + "GetUploadedFiles",
"bPaginate": true,
"sServerMethod": "POST",
"fnServerData": function (sSource, aoData, fnCallback) {

jQuery.ajax({
"type": "POST",
"url": sSource,
"data": JSON.stringify(dataObj),
"contentType": "application/json",
"success": function(result) {

fnCallback(result.d);
},
"error": function (xhr, textStatus, error) {
if (textStatus === 'timeout') {
alert('The server took too long to send the data.');
}
else {
alert('An error occurred on the server. Please try again in a minute.');
}

}
});
},

"aoColumns": [
{
"sWidth": "130px",
"mData": 0,
"mRender": function (data, type, full) {
return data;
}
},
{
"sWidth": "40px",
"sClass": '<%= ColumnClassName %>',
"mData": 1,
"mRender": function (data, type, full) {
return data;
}
},
....and so on

My returned JSON is:

"{\"iTotalRecords\":0,\"iTotalDisplayRecords\":0,\"sEcho\":0,\"sColumns\":null,\"aaData\":[[\"PayrollJul13.csv\",\"\\/Date(1377477353444)\\/\",\"MTP91883\",3,\"Tara McWiggan\",4920,false,\"\",\"NotSent\",false,6],[\"PayrollMay13.csv\",\"\\/Date(1377477353445)\\/\",\"MTP91483\",5,\"Tara McWiggan\",4320,false,\"Thomas Irving\",\"Sent\",true,0],[\"PayrollApr13.csv\",\"\\/Date(1377477353445)\\/\",\"MTP91453\",1,\"James Earl Jones\",0,false,\"\",\"NotSet\",false,0],[\"PayrollJan13.csv\",\"\\/Date(1377477353445)\\/\",\"MTP94483\",4,\"Tara McWiggan\",8320,false,\"Sadiq Pathan\",\"Sent\",false,0],[\"PayrollJan13.csv\",\"\\/Date(1377477353445)\\/\",\"MTP94463\",4,\"Tara McWiggan\",8320,false,\"Banana head\",\"Partial\",false,0],[\"PayrollJul13.csv\",\"\\/Date(1377477353445)\\/\",\"MTP94487\",2,\"Hurricane Narm\",0,false,\"\",\"NotSet\",false,0]]}"

Can anyone help me please? I'm banging my head against a wall on this one. Nothing I seem to do makes any difference and I 'think' I've set everything up correctly, although, clearly, I haven't. Thanks for your time.

--Tara

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Your JSON being returned is not JSON, but a string. You need to evaluate the JSON or better would be to have the server return it not as a string.

    Allan
  • tarayislandgirltarayislandgirl Posts: 2Questions: 0Answers: 0
    Thanks Allan. I tried several different ways of returning it. In my WebMethod, I originally had it set to return type JSON with it returning a custom class with iTotalRecords, aaData etc as properties. But I still got the same error. I will put it back to this and try it again but suspect that I've done something silly along the way.

    So does the rest of it look okay?

    Thanks for your help so far on this.

    --Tara
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    As far as I can see, yes.

    Allan
This discussion has been closed.