Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2366

How do I properly use AJAX function to get data (in my circumstance)?

$
0
0

I'd like to move away from using a manually specified "static" data source, and I would like to better understand how to use "ajax": function (data, callback, settings) to get data for my DataTables. But, I'm getting the error, Problem: DataTables warning: table id=tblEffectiveDates - invalid JSON response...

CURRENT WAY (working)
Here is an example of the (working) custom framework: http://live.datatables.net/tixokape/2/

1). I initialize the table with an empty data source: data: []
2). At the end of Init (represents user interaction), I request data from my server: webapp.doRequest('getEffectiveDates');
3). Once the data is received, I redraw the table: tblEffectiveDates.clear().rows.add(jsonStruct).draw();

AJAX WAY (not working)
Error, Problem: DataTables warning: table id=tblEffectiveDates - invalid JSON response...
Here is an example: http://live.datatables.net/tixokape/1/

1). I'm attempting to call my custom framework's AppActions inside the DT AJAX function:

                    ajax: {
                        function(data, theCallbackToExec, settings) {
                            webapp.doRequest('getEffectiveDates', form, theCallbackToExec);
                        }
                    },

2). My SQL query returns an Array of Objects. It doesn't have the {data: [{ prefix. However, even when I modify the query to include include the data prefix for json path, root('data'), INCLUDE_NULL_VALUES, it sill says invalid JSON!
3). I don't know how, or if I even need, to include the ajax.dataSrc option.
4). I pass the DT AJAX callback to my framework's doResults AppAction, getEffectiveDates, where I attempt to feed it JSON data. This is VERY similar to how @allan showed me the way to use the AJAX functions in Editor.

                if (typeof options === 'function') {

                    callbackFromDT = options;

                    callbackFromDT(jsonStruct)

                };

Any insight would be appreciated.


Viewing all articles
Browse latest Browse all 2366

Trending Articles