Jquery Ajax异步上传
<script> $(function(){ $('#filephoto').change(function(imgFile){ console.log(imgFile) var filextension = imgFile.target.value.substring(imgFile.target.value.lastIndexOf("."), imgFile.target.value.length); filextension = filextension.toLowerCase(); var file = imgFile.target.files[0], fileSize = 0; fileSize = file.size / 1024 if (fileSize > 2048) { layer.msg('不能超过2mb') return false; } if ((filextension != '.jpg') && (filextension != '.gif') && (filextension != '.jpeg') && (filextension != '.png') && (filextension != '.bmp')) { layer.msg('对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢!') return false; } var _this = this; var fd = new FormData(); fd.append("filephoto", file);//$_FILES['filephoto']['tmp_name']; $.ajax({ type: 'post', url: 'url', data:fd, processData: false, contentType: false, dataType: 'json', }).done(function (data) { if(data.returnNo == '0000') { $("#div_photo").css("background-image","url("+data.user_info.photo+")"); } else { layer.msg(data.returnInfo); } }); }); }); </script>
posted on 2018-07-20 18:35 loveking_阳 阅读(147) 评论(0) 编辑 收藏 举报