JSON 在Ajax中的转换及导出excel
$.ajax({
url: '/LaboratoryAnimalHousing/exportapplicationlist',
type: 'post',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log(data);
var json = JSON.stringify(data)
console.log(json);
var obj = JSON.parse(json);
console.log(obj);
for(let i in data){
data[i]['ename'] = data[i]['ename']['name']
data[i]['sname'] = data[i]['sname']['name']
data[i]['employee'] = data[i]['employee']['username']
data[i]['applicationdate'] = formatDate(data[i]['applicationdate'])
}
console.log(data);
var timestart = Date.now();
layui.table.exportFile('exportTable', data, 'xls');
var timeend = Date.now();
var spent = (timeend - timestart) / 1000;
layer.alert('导出耗时 '+spent+' s');
},error: function () {
setTimeout(function ({window.location.href='/LaboratoryAnimalHousing/selectApplication';},2000);
}
});