本篇用于记录如何使用jquery上传文件
<input type="file" id="upload-file2" accept=".xls,.xlsx" name="file"/>
function uploadData(){
var oMyForm = new FormData();
oMyForm.append("file", files[0]);
$.ajax({
type: "post",
url: '/ajax/upload.mapi',
async: true,
data: oMyForm,
enctype: 'multipart/form-data',
processData: false,
contentType: false,
success: function (data) {
if(data.successed){
var json=data.data.jValue;
initAttDataTable(json);
initNowDataTable(json);
nowDataTable(json.timeModels);
}else{
toNotification("错误",data.message,"error");
}
},
error: function (xhr, status, statusText) {
console.log('File upload failed ...');
}
});
var files;
$(document).ready(function(){
// initSysDataTable(2016,7,1,2016,8,31);
$("#upload-file2").on('change',prepareLoad);
function prepareLoad(event)
{
files=event.target.files;
}
})