Bug in function based ajax data source
Bug in function based ajax data source
b_levitt
Posts: 3Questions: 0Answers: 0
When setting the ajax object to a function, an error is thrown on line 3291 (ver 1.10.5). I traced the issue back to the following code:
function _fnAjaxDataSrc ( oSettings, json )
{
var dataSrc = $.isPlainObject( oSettings.ajax ) && oSettings.ajax.dataSrc !== undefined ?
oSettings.ajax.dataSrc :
oSettings.sAjaxDataProp; // Compatibility with 1.9-.
The issue seems to be that ajax.dataSrc IS undefined so sAjaxDataProp is used and the errors cascade from there.
The same issue can be seen when doing the following:
$('#DataTable').dataTable({
"ajax":
{
url: 'myjsonurl',
type: "POST"
},
However, the code pointed me to setting dataSrc to empty string and that works successfully.
$('#DataTable').dataTable({
"ajax":
{
url: 'myjsonurl',
type: "POST"
dataSrc: ""
},
This discussion has been closed.
Replies
I did eventually find a reference that describes the different functionality when setting dataSrc to "" - arrays vs an object with a data property on it. Solution was to do this where data1 was my data array:
Could you show me the code you were using when using
ajax
as a function please?Thanks,
Allan
This is the one that works:
The key was wrapping the returned data1 array with a property "data";
This is what threw an error (along with the scenario mentioned in the OP).
Got it - thanks! Yes, there is actually no option to specify
dataSrc
whenajax
is a function. That is definitely an oversight (which I must confess I'm not sure how to fix). I'll have a think about the best way of addressing this, but in the mean time, thanks for posting your workaround.What OP? Your message above is the first in this thread.
Thanks,
Allan