Object vs String?
Object vs String?
clint
Posts: 15Questions: 0Answers: 0
Ive got the following code that works:
[code]
$('#DataTables').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.aspx/DoProc",
"sServerMethod": "POST",
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallBack) {
var aoHash = {};
$.each(aoData, function() {
var item = this;
aoHash[item.name] = item.value;
});
$.ajax({
"type": "POST",
"url": sSource,
"data": JSON.stringify(aoHash),
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"success": function(msg) {
fnCallBack({"sEcho": 1,"iTotalRecords": "4","iTotalDisplayRecords": "4","aaData": [["Gecko","Firefox 1.0","Win 98 OSX.2","1.7","A"],["Gecko","Firefox 1.5","Win 98 OSX.2","1.8","A"],["Gecko","Firefox 2.0","Win 98 OSX.2","1.8","A"],["Gecko","Firefox 3.0","Win 2k OSX.3","1.9","A"]]});
},
"error": function(msg) {
var json = eval(msg);
alert("AJAX Error: " + json.d);
}
});
},
"fnServerParams": function(aoData) {
aoData.push({ "name": "procName", "value": "procGetAllContacts" });
aoData.push({ "name": "parmsVals", "value": "" });
aoData.push({ "name": "procType", "value": "Select" });
}
});
[/code]
However, when I try to use the data that is returned from the asp.net page using this code:
[code]
$('#DataTables').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.aspx/DoProc",
"sServerMethod": "POST",
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallBack) {
var aoHash = {};
$.each(aoData, function() {
var item = this;
aoHash[item.name] = item.value;
});
$.ajax({
"type": "POST",
"url": sSource,
"data": JSON.stringify(aoHash),
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"success": function(msg) {
var jsond = eval(msg);
fnCallBack(jsond);
},
"error": function(msg) {
var json = eval(msg);
alert("AJAX Error: " + json.d);
}
});
},
"fnServerParams": function(aoData) {
aoData.push({ "name": "procName", "value": "procGetAllContacts" });
aoData.push({ "name": "parmsVals", "value": "" });
aoData.push({ "name": "procType", "value": "Select" });
}
});
[/code]
I get this error:
TypeError: aData is undefined
[Break On This Error]
for ( var i=0, iLen=aData.length ; i
[code]
$('#DataTables').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.aspx/DoProc",
"sServerMethod": "POST",
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallBack) {
var aoHash = {};
$.each(aoData, function() {
var item = this;
aoHash[item.name] = item.value;
});
$.ajax({
"type": "POST",
"url": sSource,
"data": JSON.stringify(aoHash),
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"success": function(msg) {
fnCallBack({"sEcho": 1,"iTotalRecords": "4","iTotalDisplayRecords": "4","aaData": [["Gecko","Firefox 1.0","Win 98 OSX.2","1.7","A"],["Gecko","Firefox 1.5","Win 98 OSX.2","1.8","A"],["Gecko","Firefox 2.0","Win 98 OSX.2","1.8","A"],["Gecko","Firefox 3.0","Win 2k OSX.3","1.9","A"]]});
},
"error": function(msg) {
var json = eval(msg);
alert("AJAX Error: " + json.d);
}
});
},
"fnServerParams": function(aoData) {
aoData.push({ "name": "procName", "value": "procGetAllContacts" });
aoData.push({ "name": "parmsVals", "value": "" });
aoData.push({ "name": "procType", "value": "Select" });
}
});
[/code]
However, when I try to use the data that is returned from the asp.net page using this code:
[code]
$('#DataTables').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"sAjaxDataProp": "aaData",
"sAjaxSource": "test.aspx/DoProc",
"sServerMethod": "POST",
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallBack) {
var aoHash = {};
$.each(aoData, function() {
var item = this;
aoHash[item.name] = item.value;
});
$.ajax({
"type": "POST",
"url": sSource,
"data": JSON.stringify(aoHash),
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"success": function(msg) {
var jsond = eval(msg);
fnCallBack(jsond);
},
"error": function(msg) {
var json = eval(msg);
alert("AJAX Error: " + json.d);
}
});
},
"fnServerParams": function(aoData) {
aoData.push({ "name": "procName", "value": "procGetAllContacts" });
aoData.push({ "name": "parmsVals", "value": "" });
aoData.push({ "name": "procType", "value": "Select" });
}
});
[/code]
I get this error:
TypeError: aData is undefined
[Break On This Error]
for ( var i=0, iLen=aData.length ; i
This discussion has been closed.
Replies
[code]
"sAjaxDataProp": "aaData"
[/code]
and
[code]
var aoHash = {};
$.each(aoData, function() {
var item = this;
aoHash[item.name] = item.value;
});
[/code]
and
[code]
"data": JSON.stringify(aoHash),
[/code]
and
[code]
"success": function(msg) {
var jsond = eval(msg);
var b = jQuery.parseJSON(jsond.d);
fnCallBack(b);
},
[/code]
Im surprised that I couldn't find any examples earlier. The real key was this line:
[code]
jQuery.parseJSON(jsond.d);
[/code]
Simple thing to see if you know what you are doing....which I didn't :).