刷新数据表中的数据与点击Ajax调用

刷新数据表中的数据与点击Ajax调用

本文介绍了刷新数据表中的数据与点击Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表与Ajax调用。我形成的表是这样的:

I have a datatable with ajax calls. I form the table like this:

var _initTable = function() {
    $('#datatables tr').not(':first').on('click', function() {
        var dateandtime = $(this).find(':nth-child(3)').text();
        window.location.href = '/results/detail/dateandtime/' + dateandtime;
    });
};

$('#datatables').dataTable({
     bProcessing  : true,
     sProcessing  : true,
     bServerSide  : true,
     sAjaxSource  : '/results/load-results',
     fnServerParams: function ( aoData ) {
         aoData.push( {"name": "quizid", "value": quizid },{ "name": "questionid", "value": questionid } );
     },
     aoColumnDefs : [{'bSortable' : false, 'aTargets' : ['no-sort']}], // make the actions column unsortable
     sPaginationType : 'full_numbers',
     fnDrawCallback  : function(oSettings) {
         _initTable();
     }
});

正如你可以看到我送2参数,以我的PHP行动。
现在我想重新加载该表时,我点击一个按钮。因此,我想要做的就是让另一个Ajax调用和发送等参数(quizid将是相同的,但questionid会有所不同)。

As you can see I send 2 parameters to my php action.
Now I would like to reload the table when I click on a button. So what I want to do is make another ajax call and send other parameters (quizid will be the same, but the questionid will be different).

我知道你有这样的事情 oTable.fnReloadAjax(的newURL); ,但我应该怎么粘贴在的newURL参数??

I know you have something like this oTable.fnReloadAjax(newUrl); but what should I paste at the newUrl parameter??

我做了一个的jsfiddle: http://jsfiddle.net/8TwS7/

I've made a jsfiddle: http://jsfiddle.net/8TwS7/

推荐答案

您应该能够通过使用fnServerData代替fnServerParams做到这一点

you should be able to accomplish this by using fnServerData instead of fnServerParams

var oTable = $('#datatables').dataTable({
     bProcessing  : true,
     sProcessing  : true,
     bServerSide  : true,
     sAjaxSource  : '/results/load-results',
"fnServerData": function ( sSource, aoData, fnCallback ) {
            /* Add some extra data to the sender */
            aoData.push( { "name": "quizid", "value": quizid } );
            aoData.push( { "name": "question_id", "value": question_id } );
            $.getJSON( sSource, aoData, function () {
                /* Do whatever additional processing you want on the callback, then tell DataTables */
            }).done(function(json){
                fnCallback(json);
                        }).fail(function(xhr, err){
                var responseTitle= $(xhr.responseText).filter('title').get(0);
                alert($(responseTitle).text() + "\n" + formatErrorMessage(xhr, err) );
            });
        },
    });

您应该能够再调用点击功能使用fnDraw API调用上,我们对数据表初始化

you should be able to then call a click function to redraw your table no problem using the fnDraw API call on the variable we created on datatable initialization

$('#somelement').on('click', function(){

        oTable.fnDraw();
    });

这篇关于刷新数据表中的数据与点击Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:07