我想使用 AJAX 调用将值显示到表中。用于它的代码是,
initTable();
function initTable (){
return $('#exEmpListTable').dataTable({
"bPaginate": false,
"sScrollY": "200px",
"bScrollCollapse": true
});
}
function tableActions (){
var oTable = initTable();
// perform API operations with oTable
oTable.fnSort( [ [1,'desc']] );
}
$("#btnShowExEmpList").click(function (e){
var selectedShop = $('#Shop').val();
if(selectedShop == null){
alert(" Please select a shop first ");
return false;
}
if(selectedShop != null){
alert("==== Selected Shop ==== "+selectedShop);
var $exEmpDialog = $("#Dialog").dialog({
width :275,
height: 400,
resizable: false,
position: ['top', 200],
modal: true
});
$exEmpDialog.dialog('close');
$.ajax({
url : 'empReqCreateNewReq.do',
data : { getExEmpList: true, SelectedShop : selectedShop, ajaxCall : true },
method : 'GET',
dataType : 'json',
contentType: "application/json; charset=utf-8",
success : function(data) {
alert('success === ' +data.exemplist.length);
alert("======== ELEMENTS ======== "+JSON.stringify(data));
//rePopulateExEmpList(data);
//data = JSON.stringify(data);
$exEmpDialog.dialog('close');
//$(this).dialog('close')
var oTable = initTable();
oTable = $("#exEmpListTable").dataTable();
//oTable.fnClearTable(0);
oTable.oData[data];
oTable.fnDraw();
$exEmpDialog.dialog('open');
},
error : function(xhr, status) {
alert('Sorry, there was a problem while placing your ajax request. Contact Admin!');
}
});
}
//$("#Dialog").dialog();
});
运行此程序时,我可以看到警报机器人中的值。但在那之后,它会显示一条错误消息,
DataTables warning (table id = 'exEmpListTable'): Cannot reinitialise DataTable.
要检索此表的 DataTables 对象,请不向 dataTable() 函数传递任何参数,或者将 bRetrieve 设置为 true。或者,要销毁旧表并创建新表,请将 bDestroy 设置为 true(请注意,可以通过 API 对配置进行很多更改,这通常会更快)。
请帮我解决这个问题。