47

データテーブル ajax 呼び出しの成功で JavaScript 関数を呼び出すことは可能ですか。使用しようとしているコードは次のとおりです。

var oTable = $('#app-config').dataTable(
            {
                "bAutoWidth": false,                                                
                "bDestroy":true,
                "bProcessing" : true,
                "bServerSide" : true,
                "sPaginationType" : "full_numbers",
                "sAjaxSource" : url,                    
                "fnServerData" : function(sSource, aoData, fnCallback) {
                    alert("sSource"+ sSource);
                    alert("aoData"+ aoData);
                    $.ajax({
                        "dataType" : 'json',
                        "type" : "GET",
                        "url" : sSource,
                        "data" : aoData,
                        "success" : fnCallback
                    });
                }

次のようなものを持つことは可能ですか?

success : function(){
    //.....code goes here
}

"success" の代わりに: fnCallback ------> AJAX 呼び出しの最後の行です。この関数では、サーバー側から送信された値を確認したいと思います。助けてくれてありがとう....

4

9 に答える 9

70

dataSrc を使用できます:

これは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" }
        
        ]
    } );
于 2014-08-05T15:40:58.823 に答える
42

これを使用できます:

"drawCallback": function(settings) {
   console.log(settings.json);
   //do whatever  
},
于 2015-07-21T02:57:40.443 に答える
41

私が見つけた最善の方法は、データが取得されてテーブルがレンダリングされた後に起動するinitCompleteメソッドを使用することです。ただし、これは一度しか起動しないことに注意してください。

$("#tableOfData").DataTable({
        "pageLength": 50,
        "ajax":{
            url: someurl,
            dataType : "json",
            type: "post",
            "data": {data to be sent}
        },
        "initComplete":function( settings, json){
            console.log(json);
            // call your function here
        }
    });
于 2017-06-01T14:29:55.287 に答える
-1

次のコードを試してください。

       var oTable = $('#app-config').dataTable(
        {
            "bAutoWidth": false,                                                
            "bDestroy":true,
            "bProcessing" : true,
            "bServerSide" : true,
            "sPaginationType" : "full_numbers",
            "sAjaxSource" : url,                    
            "fnServerData" : function(sSource, aoData, fnCallback) {
                alert("sSource"+ sSource);
                alert("aoData"+ aoData);
                $.ajax({
                    "dataType" : 'json',
                    "type" : "GET",
                    "url" : sSource,
                    "data" : aoData,
                    "success" : fnCallback
                }).success( function(){  alert("This Function will execute after data table loaded");   });
            }
于 2017-12-28T08:54:42.737 に答える