在添加项目时,datagrid不会自动更新。刷新时仅显示记录。 在以下代码中需要执行的操作以自动更新表而无需刷新。 网址是我用来添加商品的其余API
function addItem(){
var data = null;
var addItem = new XMLHttpRequest();
addItem.withCredentials = true;
var eName = $('#txtempname').val();
var eDesg = $('#txtdesignation').val();
addItem.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
addItem.open("POST", "url");
addItem.setRequestHeader("authorization", "Basic cGR4OnBkeA==");
addItem.setRequestHeader("name", eName);
addItem.setRequestHeader("description",eDesg );
addItem.setRequestHeader("cache-control", "no-cache");
addItem.setRequestHeader("postman-token", "320fb698-18d9-790b-3471-3528ec60d948");
addItem.send(data);
$.ajax(
{
type:'POST',
url: 'url',
success:function(){
//s console.log("added succesfully");
swal("Added!", "Catalog Added successfully", "success");
getItems();
if ($.fn.DataTable.isDataTable('#subsiteList')) {
$('#subsiteList').DataTable().destroy();
}
$('#subsiteList tbody').empty();
},
error:function(){
console.log("error");
}
}
);
}