单击时使用ajax调用重新加载数据表数据

我有一个带有ajax调用的数据表。 我形成这样的表格:

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(); } }); 

如你所见,我向我的php动作发送2个参数。
现在我想在点击按钮时重新加载表格。 所以我想做的是进行另一个ajax调用并发送其他参数(quizid将是相同的,但是questionid将是不同的)。

我知道你有这样的东西oTable.fnReloadAjax(newUrl); 但是我应该在newUrl参数上粘贴什么?

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

您应该能够通过使用fnServerData而不是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调用来调用click函数重绘表没问题

 $('#somelement').on('click', function(){ oTable.fnDraw(); });