来处理。如下代码:
/**上传execl*/
uploadExcel: function () {
var button = $('#excel');
var upload_url = commonAjax.defaultOption.cms_url + 'salary/uploadExcel.do';
var upload_name = 'file';
var loading =null;
new AjaxUpload(button,{
action: upload_url,
name: upload_name, //这相当于<input type = "file" name = "shanghaiFile"/>
onSubmit : function(file, ext){
if (ext && /^(xls|xlsx)$/.test(ext)){
loading = layer.load(2, {shade: 0.1});
} else {
layer.msg('非excel格式,请重传!');
return false;
}
},
onComplete: function(file, response){ //上传完毕后的操作
layer.close(loading);
console.log(response);
//解析源码
var data = $.parseJSON(response.replace(/<.*?>/ig,""));
if (data.resCode==0) {
layer.msg("上传成功!")
salary.getSalaryList(1);
} else {
layer.msg('excel上传失败!请核对列名');
}
}
});
},