當我手動重繪(通過按鈕單擊)時,我的jQuery數據表似乎發佈兩次 - 我怎樣才能防止數據表這樣做?datatables fnDraw使多個AJAX請求
這裏是我的客戶端代碼:
$(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的兩倍),而且它的撞擊着我的動作兩次通過設置一個斷點。我無法找到任何理由這樣做。謝謝!