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

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

HTML代码很简单:

input >

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);
                    }
                }  
            });
      }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-07-09
  • 2022-12-23
  • 2021-11-20
  • 2021-06-17
  • 2021-11-16
  • 2021-12-01
相关资源
相似解决方案