使用jquery数据表基于用户搜索使用ajax显示数据。数据表没有刷新。当我点击下一个或上一个按钮时,它显示第一次加载的值。
function searchCustomer() {
var frm = $("#customerDetailSearchForm").serializeObject();
$("#tbl_contact_search_result").hide();
$.ajax({
type: 'POST',
url: restContextPath + '/IONSWeb/rest/order/searchContact',
data: JSON.stringify(frm),
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(data, status, xhr) {
$("#tbl_contact_search_result tbody").empty();
$.each(data.body, function(i, item) {
var checkBox = item.actionString;
var dataTableBodyHTML = '<tr><td>'+ checkBox + '</td><td>'+ item.name + '</td><td>'+ item.street +'</td><td>' + item.city + '</td><td>'+ item.state + '</td><td>' + item.phone +'</td></tr>';
$("#tbl_contact_search_result tbody").append(dataTableBodyHTML);
$("#tbl_contact_search_result").show();
});
var dataTable = $('#tbl_contact_search_result').DataTable();
},
error: function(jqXhr, textStatus, errorMessage) {
$('.ErrorMsg').html('<h5>An error has occurred</h5>');
}
});
}
答案 0 :(得分:0)
只需禁用ajax缓存功能即可。 The default value is true。所以,你必须将其设置为false。 (cache:false)
function searchCustomer() {
var frm = $("#customerDetailSearchForm").serializeObject();
$("#tbl_contact_search_result").hide();
$.ajax({
type: 'POST',
url: restContextPath + '/IONSWeb/rest/order/searchContact',
data: JSON.stringify(frm),
dataType: 'json',
cache: false,
contentType: "application/json; charset=utf-8",
success: function(data, status, xhr) {
$("#tbl_contact_search_result tbody").empty();
$.each(data.body, function(i, item) {
var checkBox = item.actionString;
var dataTableBodyHTML = '<tr><td>'+ checkBox + '</td><td>'+ item.name + '</td><td>'+ item.street +'</td><td>' + item.city + '</td><td>'+ item.state + '</td><td>' + item.phone +'</td></tr>';
$("#tbl_contact_search_result tbody").append(dataTableBodyHTML);
$("#tbl_contact_search_result").show();
});
var dataTable = $('#tbl_contact_search_result').DataTable();
},
error: function(jqXhr, textStatus, errorMessage) {
$('.ErrorMsg').html('<h5>An error has occurred</h5>');
}
});
}