数据表未自动更新

时间:2018-11-25 12:12:11

标签: javascript jquery ajax rest datatables

在添加项目时,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");
                   }
                }
              );


}

1 个答案:

答案 0 :(得分:0)

也许您应该对我下面的类似问题持保留态度:-Refrence link