JSON object in txt file works fine, same object in variable dies, please help!
JSON object in txt file works fine, same object in variable dies, please help!
Please help, I'm pulling my hair out here. If I try to bind directly to the data variable, I get the error, " Requested unknown parameter 'FirstName' from the data source for row 0". However, if I copy/paste the value of the data object into a text file, and then reference it with aAjaxSource, it works just fine. What am I doing wrong here?
[code]
function populateSummaryResults(ajaxContext) {
var data = ajaxContext.responseText;
$('#example').dataTable({
//"aaData": data, <--- This throws an error
sAjaxSource: '/Scripts/data.txt', // <-- This with the same value as the data variable works fine.
"aoColumns": [
{ "sTitle": "First Name", "mDataProp": "FirstName" },
{ "sTitle": "Last Name", "mDataProp": "LastName" },
]
});
}
[/code]
[code]
function populateSummaryResults(ajaxContext) {
var data = ajaxContext.responseText;
$('#example').dataTable({
//"aaData": data, <--- This throws an error
sAjaxSource: '/Scripts/data.txt', // <-- This with the same value as the data variable works fine.
"aoColumns": [
{ "sTitle": "First Name", "mDataProp": "FirstName" },
{ "sTitle": "Last Name", "mDataProp": "LastName" },
]
});
}
[/code]
This discussion has been closed.
Replies
var data = jQuery.parseJSON(ajaxContext.responseText);
before passing the data variable to dataTable.