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!

shlapshlap Posts: 3Questions: 0Answers: 0
edited April 2012 in General
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]

Replies

  • shlapshlap Posts: 3Questions: 0Answers: 0
    Nevermind, I got it, I had to use:

    var data = jQuery.parseJSON(ajaxContext.responseText);

    before passing the data variable to dataTable.
This discussion has been closed.