【发布时间】:2015-05-23 13:30:03
【问题描述】:
当我在单选按钮选择事件 ajax 结果更新但 DataTable 显示旧数据时重新加载 ajax 数据时,我遇到了刷新 DataTable 的问题 它在控制台上显示以下消息 -
DataTables warning: table id=sample_1 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
我用谷歌搜索了这个警告,但对我来说似乎没有任何帮助。
下面是我正在使用的js文件
jquery.dataTables.js
jquery.dataTables.min.js
table-data.js
下面是我的ajax方法
$.ajax({
url: "manual-json.php",
type: "POST",
datatype: 'json',
data: 'jobid=' + $('#jobid').val() + '&matchgroup=' + $('input:radio[name=matchgroup]:checked').val(),
success: function(result) {
alert(result);
var res = "";
data = $.parseJSON(result);
for (var key in data) {
if (data.hasOwnProperty(key)) {
if (data[key].matchStatusID == 7) {
res = res + "<tr id='tab-row'><td colspan='4'><form id='formData" + i + "' onsubmit='formsubmit(this)' method='post' style='margin-bottom: 0;'><table width='100%'><tr><td width='34%'><input type='hidden' name='manualMatchResoulationDetailID' id='manualMatchResoulationDetailID' value='" + data[key].manualMatchResoulationDetailID + "'><input type='hidden' name='matchStatusID' id='matchStatusID' value='" + data[key].matchStatusID + "'><input type='hidden' name='processName" + i + "' id='processName" + i + "' value=''><input type='hidden' name='id' id='id' value='" + i + "'><input type='hidden' name='jobid' id='jobid' value='<?php echo $jobid; ?>'><label id='secondaryData' style='font-size:13px;'>" + data[key].secondaryData + "</label></td><td width='33%'><label id='primaryData' style='font-size:13px;'>" + data[key].primaryData + "</label></td><td width='16%'><label id='searchScore' style='font-size:13px;'>" + data[key].searchScore + "</label></td><td width='17%'><button class='btn btn-blue' id='change" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>Change</button><button class='btn btn-blue' id='unmatch" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>Unmatch</button></td></tr></table></form></td></tr>";
} else if (data[key].matchStatusID == 8) {
res = res + "<tr id='tab-row'><td colspan='4'><form id='formData" + i + "' onsubmit='formsubmit(this)' method='post' style='margin-bottom: 0;'><table width='100%'><tr><td width='34%'><input type='hidden' name='manualMatchResoulationDetailID' id='manualMatchResoulationDetailID' value='" + data[key].manualMatchResoulationDetailID + "'><input type='hidden' name='matchStatusID' id='matchStatusID' value='" + data[key].matchStatusID + "'><input type='hidden' name='processName" + i + "' id='processName" + i + "' value=''><input type='hidden' name='id' id='id' value='" + i + "'><input type='hidden' name='jobid' id='jobid' value='<?php echo $jobid; ?>'><label id='secondaryData' style='font-size:13px;'>" + data[key].secondaryData + "</label></td><td width='33%'><label id='primaryData' style='font-size:13px;'>" + data[key].primaryData + "</label></td><td width='16%'><label id='searchScore' style='font-size:13px;'>" + data[key].searchScore + "</label></td><td width='17%'><button class='btn btn-blue' id='match" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>Match</button><button class='btn btn-blue' id='unmatch" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>UnReject</button></td></tr></table></form></td></tr>";
} else {
res = res + "<tr id='tab-row'><td colspan='4'><form id='formData" + i + "' onsubmit='formsubmit(this)' method='post' style='margin-bottom: 0;'><table width='100%'><tr><td width='34%'><input type='hidden' name='manualMatchResoulationDetailID' id='manualMatchResoulationDetailID' value='" + data[key].manualMatchResoulationDetailID + "'><input type='hidden' name='matchStatusID' id='matchStatusID' value='" + data[key].matchStatusID + "'><input type='hidden' name='processName" + i + "' id='processName" + i + "' value=''><input type='hidden' name='id' id='id' value='" + i + "'><input type='hidden' name='jobid' id='jobid' value='<?php echo $jobid; ?>'><label id='secondaryData' style='font-size:13px;'>" + data[key].secondaryData + "</label></td><td width='33%'><label id='primaryData' style='font-size:13px;'>" + data[key].primaryData + "</label></td><td width='16%'><label id='searchScore' style='font-size:13px;'>" + data[key].searchScore + "</label></td><td width='17%'><button class='btn btn-blue' id='match" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>Match</button><button class='btn btn-blue' id='reject" + i + "' type='button' style='padding: 2 2px;font-size: 13px;margin-right: 5px;margin-left: 10px; width: 58px;' onclick='matchprocess(" + i + ",this.id)'>Reject</button></td></tr></table></form></td></tr>";
}
i = i + 1;
}
}
res = restr + res;
res = res + '</tbody>';
$("#sample_1").append(res);
TableData.init();
},
error: function() {
$("#result").addClass('msg_error');
}
});
【问题讨论】:
-
你试过
$('#sample_1').destroy(); -
为什么同时使用 jquery.dataTables.js 和 jquery.dataTables.min.js?对一个代码不可复现的问题投了 6 票?
-
“我搜索了这个警告,但似乎对我没有任何帮助”,警告本身呢 - 有关此错误的更多信息,请参阅datatables.net/tn/3 ??
-
该错误仅表示您正在初始化数据表两次。删除其中一个数据表 js 文件,并确保在初始化新的数据表之前销毁以前的数据表。除此之外,不能告诉你这里可能出了什么问题。
-
@markpsmith:是的....不工作
标签: jquery ajax datatable jquery-datatables