ajax.reload() callback argument undefined
ajax.reload() callback argument undefined
On the page for ajax.reload()
the first parameter of the ajax.reload function is a callback for after the reload completes. The page goes on to state that this callback is passed a single argument: the data received upon reloading of the table. I have implemented a DataTable using the ajax
function option to implement my own AJAX call. Everything is working perfectly except that the callback called by the ajax.reload function is passed an undefined argument. I need to see this argument in the callback and would like to know if I am doing anything wrong that might be causing this issue.
The code below is a condensed version of what I am implementing for this project.
Here is the ajax function passed to the DataTable initializer.
function (data, callback, settings) {
//Preparing the args...
var args = "blah blah blah";
//Making the AJAX request
ajaxRequest(args, function(response) {
var callbackData = {
recordsFiltered: response.totalRecords,
data: response.data;
};
callback(callbackData);
});
}
Answers
So, I figured out what I need to do. The ajax.reload function uses the ajax.json function to get the AJAX response data which it passes to the ajax.reload callback. This response data is normally stored by the default ajax function. Because I overloaded this function, the response data wasn't being set. To set the response data so that the ajax.json function works properly, you have to set the settings.json to be the response data, settings being the last argument in the ajax function.
So, the new ajax function would look like this: