ajax
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: "http://106.54.141.65:8088/fileUpload/uploadImg",
type: 'POST',
data: formData,
dataType: 'JSON',
cache: false,
processData: false,
contentType: false
}).done(function (ret) {
console.log(ret)
if(ret.success) {
console.log('上传成功');
} else {
console.log('上传失败');
}
});
axios
<input type="file" name="" id="" value="" @change="addImg($event)" class="opacityImg"/>
<script src="https://lib.baomitu.com/axios/0.19.2/axios.min.js" type="text/javascript" charset="utf-8"></script>
addImg(el,idx,dom){
let _this=this;
var file = el.target.files;
var formData = new FormData();
formData.append("file", file[0]);
var imgType = file[0];
var type = imgType.type.split('/')[0];
console.log(file[0])
axios({
method:'POST',
url:'xxxx/fileUpload/uploadImg',
headers: {
'Content-Type':'multipart/form-data',
},
data: formData
})
.then(function (response) {
console.log('上传成功');
})
.catch(function (error) {
console.log('上传失败');
layer.msg("重新上传")
});
},
网友评论