javascript - datatable is displaying old value when i click next or previous button. -
im using jquery datatable displaying data based on user search using ajax. datatable not refreshing. displaying first time loaded value when click next or previous button.
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>'); } }); }
just disable ajax caching feature. the default value true. so, have set 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>'); } }); }
Comments
Post a Comment