当我手动重绘(通过单击按钮)时,我的 jquery 数据表似乎发布了两次 - 如何防止数据表这样做?
这是我的客户端代码:
$(document).ready(function () {
dataTable = $('#Results').dataTable({
"bLengthChange": true,
"bFilter": false,
"bSort": true,
"bInfo": true,
"bAutoWidth": false,
"sPaginationType": "bootstrap",
"sDom": "ftrpli",
"bServerSide": true,
// "sAjaxSource": "AjaxControllerAction",
"fnServerParams": function (aoData) {
aoData.push({ "name": "UserId", "value": $('#UserId').val() });
aoData.push({ "name": "Data", "value": $('#Data').val() });
aoData.push({ "name": "Location", "value": $('#Location').val() });
},
"fnServerData": function (sSource, aoData, fnCallback) {
showProgress();
var headers = {};
headers['__RequestVerificationToken'] = token;
alert('zzzz');
$.ajax({
dataType: 'json',
type: 'POST',
//url: sSource,
url: 'AjaxControllerAction',
data: aoData,
headers: headers,
success: function (json) {
hideProgress();
fnCallback(json);
},
error: function (json) {
hideProgress();
}
});
},
"fnDrawCallback": function () { hideProgress(); },
"bProcessing": false,
"aoColumns": [
{ "sName": "NAME",
"fnRender": function (oObj) {
return '<a href="Details/' +
oObj.aData[0] + '">' + oObj.aData[0] + '</a>';
}
},
{ "sName": "DATA" },
{ "sName": "DATA1" },
{ "sName": "DATA2" },
]
});
}
);
$("#SearchForm").on("submit", function (event) {
event.preventDefault();
// this sends the request twice ??
dataTable.fnDraw();
});
我知道它击中了我的 AjaxControllerAction 两次,从使用两个萤火虫(我看到 xmlhttprequest 两次)和它通过设置断点击中我的动作两次。我找不到它会这样做的任何理由。谢谢!