JS图片压缩上传处理

来源:互联网 发布:java自动装箱和拆箱 编辑:程序博客网 时间:2024/06/05 19:36

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>



原创粉丝点击