前端图片上传

做项目用到图片上传,遇到一个别人写的不错的插件,插件小,方便,在这写一下保存方便以后再次用到

 
  var u1 = new UploadPic();
u1.init({
selector: '#fileImage',
callback: function(base64,input,u) {
$.ajax({
url: baseUrl+'/api/v1/file/uploadBase64File',
data: {imageFile: base64, fileType: '0', ctype: 'local', 'base64':'base64','filename':u.fileName},
type: 'post',
dataType: 'json',
success: function(i) {
alert(i.data);
var textHtml = "<img class='imgFile' src='"+i.data+"'/>";
$("#showImg").append(textHtml);
//input.prev().prev().remove();
//input.prev().attr('src',i.data).css('display','block');;
//input.next().val(i.key);
//jq.show_tip('上传成功!');
}
})
},
loading: function() {
//jq.show_tip('上传中!');
}
});
 

插件和原文的地址:https://github.com/lunnlew/wx_upload_by_file

posted @ 2018-05-21 14:40  青青子衿619  阅读(319)  评论(0编辑  收藏  举报