以导入excel为例
function ImportExcel() {
var files = document.getElementById("file_upload").files;
var formdata_file = new FormData();
formdata_file.append("file", files[0]);
var userId = '001';
$.ajax({
url: '../../api/securityRisk/importRiskStandard?modify='+userId,
type: 'POST',
data: formdata_file,
//contentType: "application/json",
contentType: false,//ajax2.0可以不用设置请求头,但是jq帮我们自动设置了,这样的话需要我们自己取消掉
processData: false,//取消帮我们格式化数据,是什么就是什么
dataType: 'json',
//headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
//},
success: function (res) {
if (res.code == 0) {
alert(res.message);
}
else {
alert('数据导入成功!');
}
},
error: function (e) {
alert('数据导入失败!');
}
});
return false;
}