问题描述
我使用的数据表显示一些数据。当一个新的记录添加(通过AJAX),我试图重新加载成功的表。我得到的错误oTable没有定义每当我试图打电话或者oTable.fnDraw()或oTable.fnReloadAjax()。我究竟做错了什么?
我曾经尝试都fnDraw()和fnReloadAjax()和都返回相同的错误。
$(文件)。就绪(函数(){
VAR oTable = $('。admin_users)。dataTable中({
bProcessing:真实,
sAjaxSource:SQL / admin_users.php',
aaSorting:[[0,递增]],
bJQueryUI:真实,
sPaginationType:full_numbers,
//sAjaxSource:SQL / dataTable.php',
bStateSave:真正的,//使用cookie保存的项目当前的显示
aoColumns:[
空值,
空值,
空值,
空值,
{S型:日,的sclass:中心}
]
bScrollCollapse:真实,
sScrollX:100%
});
oTable.fnAdjustColumnSizing();
手动重新绘制按钮:
$('#click_me)。点击(函数(){
oTable.fnDraw();
//oTables.fnReloadAjax();
});
oTable
是一个局部变量引用的数据表中是没有这个文件准备好功能之外有效。
做到这一点,而不是:
$('#click_me)。点击(函数(){
$('admin_users。')的dataTable()fnReloadAjax()。;
});
I am using DataTables to display some data. When a new record is added (via AJAX), I am trying to reload the table on success. I get the error "oTable is not defined" whenever I try to call either oTable.fnDraw() or oTable.fnReloadAjax(). What am I doing wrong?
I have tried both fnDraw() and fnReloadAjax() and both return the same error.
$(document).ready(function(){
var oTable = $('.admin_users').dataTable({
"bProcessing": true,
"sAjaxSource": 'sql/admin_users.php',
"aaSorting": [[ 0, "asc" ]],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
// "sAjaxSource": 'SQL/dataTable.php',
"bStateSave": true, //Use a cookie to save current display of items
"aoColumns": [
null,
null,
null,
null,
{ "sType": "date", "sClass":"center" }
],
"bScrollCollapse": true,
"sScrollX": "100%"
});
oTable.fnAdjustColumnSizing();
Manual Re-Draw Button:
$('#click_me').click( function () {
oTable.fnDraw();
//oTables.fnReloadAjax();
});
oTable
is a local variable reference to the datatable that is not valid outside the document ready function.
Do this instead:
$('#click_me').click( function () {
$('.admin_users').dataTable().fnReloadAjax();
} );
这篇关于JQuery的数据表 - AJAX重新加载不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!