首页 > 代码库 > ajax图片上传

ajax图片上传

html

<from method="POST" enctype="multipart/form-data" id="aaa" class="banneredit_from"> 
           <p>文件:<input class="banneredit_input" type="file" name="file" id="bbb" /></p>
           <p><button value=http://www.mamicode.com/"上传" id="abc" >上传</button></p>
</from>

jquery

$(‘#abc‘).on(‘click‘,function(){
                var formData = http://www.mamicode.com/new FormData($( "#aaa" )[0]);
                formData.append(‘file‘, $("#bbb")[0].files[0]);  
                $.ajax({
                   url: "/appmanager/bannerController/bannerUploadImg",
                   type: "POST",
                   data: formData,  
                   contentType: false,  
                   processData: false, 
                   success: function(msg){
                     console.log(msg)
                   }
                });
})

@

ajax图片上传