Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

datatables 这样获取时间后台搜索时间段获取数据重新渲染应该怎么写成功的回调函数????求大神解答

   // 点击查询按钮
        $("#carBtn").on('click', function () {
            $.ajax({
                url: '',
                type: 'POST',
                // 开始时间和结束时间传给你
                data: {minDate: $(".startCreateTime").val(), maxDate: $(".endCreateTime").val()},
                async: false,
                cache: false,
                contentType: false,
                 processData: false,
                success: function (data) {
                    alert('获取到数据之后的操作');
                }
            });
        })
    });
    
    
    
    
    

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

不应该是这么写的,datatables 自己有方法来刷新的,一般来说是不需要手工来写 ajax 的

$('#_list').DataTable({
    dom: "Brtip",
    serverSide: true,
    processing: true,
    order: [[3, 'desc']],
    ajax: {
        url: URL_PREFIX + schema.API.UM_LIST.url,
        type: 'get',
        data: function (data) {
            // data['conditions'] = $('#_query_form').serializeArray();
            data['keyword'] = self.keyword
            data['workGroupID'] = self.workGroupID
        },
        error: function(resp) {
            if (resp.status == 403) {
                toastr.info('没有权限访问')
                self.loadUser()
            }
        },
        beforeSend: oauthHeaders
    }
)

当数据变动的时候(点击按钮的时候),你应该要把值设置进 data 方法里,然后调用$('#_list').DataTable().ajax.reload()就会刷新了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...