移动端头像上传AJax input file

jQuery中的Ajax不能支持 input file 需要用ajaxupload.js但是先需要引入jQuery文件 

<script src="__PUBLIC__/js/ajaxfileupload.js"></script>

HTML代码很简单:

input id="upfiles" class="upfiles" type="file" name="log" onchange="uploadImage();">

js代码:

      function uploadImage(){
            $.ajaxFileUpload({  
                url:"{:U('User/uploadImage')}",  
                secureuri:false,  
                fileElementId:'upfiles',//file标签的id  
                dataType: 'json',//返回数据的类型  
                //data:{name:'logan'},//一同上传的数据  
                success: function (data, status) {  
                    var obj = jQuery.parseJSON(data);  
                    if (obj.code == "0") {
                        $(".upload-new-img").attr("src",obj.fileName);
                    }else{
                        alert($obj.msg);
                    }
                }  
            });
      }

  

原文地址:https://www.cnblogs.com/share123/p/5478524.html