How to redirect ajax callback to my callback function?

How to redirect ajax callback to my callback function?

nklean01nklean01 Posts: 2Questions: 1Answers: 0
edited February 2016 in Free community support

Hello. I am using the custom data get function

function ajax( data, callback, settings )

so that I can do a custom asynchronous callback using my application and then give the retrieved data to data tables. Data Table's ajax function expects a JSON object in the callback parameter. How can I let data tables know that my asynchronous procedure has finished and give it the retrieved data to display it? If possible, please give me a short example in Javascript.

Thank you very much

This question has an accepted answers - jump to answer

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29
    Answer ✓

    dataTables uses the normal jquery ajax methods, so you can have a "complete": option.

    After the ajax method completes, I call a function to swap all the checkboxes for a fancy checkbox.

      , "ajax": {
                      url: "calendar_ajax.aspx?method=showrecurringevents_load&method=showrecurringevents&id=0&id2=0&newvalue=&cal_id=3188&t=1455268695315&coreid="
                    , dataType: "json" 
                    ,  complete: function() {
                         paintcheckboxes("recurringtable")
                       }
                    , error: function (xhr, error, thrown) {
                                   alert("An error occurred while attempting to retrieve data via ajax.\n"+thrown );
                                 }
      ,           }
    

    But, if you don't mind a suggestion ... Why would you not simply change the ajax: to call either your function or URL and return json formatted data instead? That is the best and easiest way in my opinion to get exactly what you want pushed into the table itself.

  • nklean01nklean01 Posts: 2Questions: 1Answers: 0

    Thank you very much for your reply. I actually solved the problem using the function ajax( data, callback, settings ). Within this function I assigned the callback to another global function in my code, let's say myFunction(), and thus myFunction() was overwritten by DataTables callback function. Then whenever my asynchronous procedure retrieved the data it could call myFunction() and that would update the table with the retrieved data.

This discussion has been closed.