H5上传图片转为Bash64传到后台

xiaoxiao2021-02-28  71

js代码:

$(document).ready(function(){ var input = document.getElementById("sendImageFile"); input.addEventListener('change',fileUpload,false); }); function fileUpload(){ var file = this.files[0]; var fileReader = new FileReader(); // alert(file.type); if(!/image\/\w+/.test(file.type)){ alert("文件必须为图片!"); return false; } fileReader.readAsDataURL(file); fileReader.onload = function(e){ // alert(this.result); //往后台上传 // --submit_imagesBase64Api $.ajax({ url:'submit_imagesBase64Api.do',// 跳转到 action data:{ imageData:this.result }, type:'post', cache:false, dataType:'json', success:function(data) { if(data.errorCode==0){ //成功 }else{ alert(data.errorMsg); } }, error : function() { } }); } }HTMl代码: <input type="file" id="sendImageFile" style="width: 0px;height: 0px;" >
转载请注明原文地址: https://www.6miu.com/read-1450285.html

最新回复(0)