無需用到插件,直接ajax就可以上傳文件,請看代碼
<input οnchange="uploadFile(this);" type="file" name="files"/>
function uploadFile(item){
var _this = $(item);
var fileObj = _this.get(0).files;
if(fileObj.length == 0){
return;
}
//這個是關鍵
var formdata = new FormData();
formdata.append("files", fileObj[0]);
$.ajax({
type:"post",
url:"../upload/uploadFile.do",
data:formdata,
dataType:"json",
// async:false,
cache : false,
contentType : false,
processData : false,
success:function(result){
},
error:function(result){
}
});
}