简体   繁体   English

在jquery / javascript中服务器端分页调用时,数据表需要成功功能

[英]Datatable require success function at the time of server side pagination call in jquery/javascript

We require success method in bellow javascript/jquery Datatable function. 在下面的javascript / jquery Datatable函数中,我们需要成功方法。 It is possible?, Because i want show alert Msg after successfully get Data from server side pagination. 有可能吗?,因为我想从服务器端分页成功获取数据后显示警报消息。

table = $('#TempTable').DataTable({

destroy: true,
"processing": true,
"serverSide": true,
"lengthMenu": [[5, 10], [5, 10]],
"ajax":{
    url :"userBack.php",
    data: {  getTemp : Temp},
    type: "post",  // method  , by default get
    error: function(){  
        $(".Table-error").html("");
        $("#Table").append('<tbody class="Table-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
        $("#Table").css("display","none");
        switchLoader(false);
    }
},
"columns": [
    {"data": "id"},
    {"data": "name"}

]

} ); });

jQuery datatables is coded to use the success callback in ajax and it breaks if you intercept it. jQuery数据表被编码为在ajax中使用成功回调,如果您拦截它,它将中断。 Source 资源

You can also make use of jQuery ajax dataFilter callback . 您还可以使用jQuery ajax dataFilter回调

$('table[id=entries]').DataTable({
    processing: true,
    serverSide: true,
    ajax: {
        type: 'POST',
        url: 'http://example.com/entries',
        dataFilter: function(response) {
            var json_response = JSON.parse(response);
            if (json_response.recordsTotal) {
                alert("There're entries");
            }else{
                alert("There're no entries");
            }
            return response;
        },
        error: function (xhr) {
            console.error(xhr.responseJSON);
        }
    }
});

Note: Return a String , not JSON in dataFilter callback. 注意:在dataFilter回调中返回String ,而不是JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM