call a function in success of datatable ajax call

后端 未结 10 1950
难免孤独
难免孤独 2020-12-29 01:44

Is that possible to invoke a javascript function in success of datatable ajax call. Here is the code am trying to use,

var oTable = $(\'#app-config\').dataTa         


        
相关标签:
10条回答
  • 2020-12-29 02:25
      "success" : function(data){
           //do stuff here
            fnCallback(data);
       }
    
    0 讨论(0)
  • 2020-12-29 02:29

    For datatables 1.10.12.

    $('#table_id').dataTable({
      ajax: function (data, callback, settings) {
        $.ajax({
          url: '/your/url',
          type: 'POST',
          data: data,
          success:function(data){
            callback(data);
            // Do whatever you want.
          }
        });
      }
    });
    
    0 讨论(0)
  • 2020-12-29 02:32

    You can use dataSrc :

    Here is a typical example of datatables.net

    var table = $('#example').DataTable( {
        "ajax": {
                "type" : "GET",
                "url" : "ajax.php",
                "dataSrc": function ( json ) {
                    //Make your callback here.
                    alert("Done!");
                    return json.data;
                }       
                },
        "columns": [
                { "data": "name" },
                { "data": "position" },
                { "data": "office" },
                { "data": "extn" },
                { "data": "start_date" },
                { "data": "salary" }
    
            ]
        } );
    
    0 讨论(0)
  • 2020-12-29 02:35

    This works fine for me. Another way don't work good

                    'ajax': {
                        complete: function (data) {
                            console.log(data['responseJSON']);
                        },
                        'url': 'xxx.php',
                    },
    
    0 讨论(0)
提交回复
热议问题