bootstrap jquery dataTable 异步ajax刷新表格数据的实现方法
异步请求
var postData = { "env_name" : new_env_name, "env_url": new_env_url, "env_desc" : new_env_desc }; $.ajax({ type: 'POST', url : '/test_env_add/', data : postData, dataType : 'json', success : function(data){ $('#table_test_env').dataTable().fnClearTable(); //清空表格 $('#table_test_env').dataTable().fnAddData(packagingdatatabledata(data),true); //刷下表格 $("#modal-container-648308").modal("hide"); }, error:function(data){ alert("新增失败"); } })
数据处理函数packagingdatatabledata,异步请求返回的data.test_env_all必须是一个json格式数据
function packagingdatatabledata(data){ var editHtml='<button href="#modal-container-648308" rel="external nofollow" data-toggle="modal" class="btn btn-xs btn-info" onclick="test_env_modify(this)"> <i class="icon-edit bigger-120"></i> </button> <button href="#modal-container-648300" rel="external nofollow" data-toggle="modal" class="btn btn-xs btn-danger" onclick="test_env_delete(this)"> <i class="icon-trash bigger-120"></i> </button>'; var a=[]; //全部行数据的list var banddata = data.test_env_all; for(var key in banddata){ var tempObj=[]; //一行数据的list tempObj.push(banddata[key].id); tempObj.push(banddata[key].name); tempObj.push(banddata[key].url); tempObj.push(banddata[key].desc); tempObj.push(editHtml); a.push(tempObj); } return a; }
相关推荐
TONIYH 2020-07-22
83510998 2020-07-18
wcqwcq 2020-06-26
delmarks 2020-06-14
ppsurcao 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03