JS图片上传使用 localResizeIMG 插件,github下载地址如下:
https://github.com/think2011/localResizeIMG
HTML代码:
<input type="file" class='photo_input' accept="image/*" />
JS代码:
导入下载好的
<script src="js/lrz.all.bundle.js"></script>
<script>
$(".photo_input").each(function(){
var that = this;
$(this).change(function(){
lrz(this.files[0])
.then(function (rst) {
$.ajax({
url:"upload_json.php",
type:"post",
dataType:'json',
data: rst.formData,
cache: false,
contentType: false,
processData: false,
success:function(data){
// 成功操作
},
error:function (data){
// 失败操作
}
});
})
.catch(function (err) {
// 处理失败会执行
alert(err);
})
.always(function () {
// 不管是成功失败,都会执行
});
});
});
</script>