上传文件,使用new FormData()

这个方法只支持到IE10,IE10以下不支持new FormData();

html:

<input style="width: 80%;" type ="text"  placeholder='选择医生照片路经 (可选)' disabled="disabled" id="choiceimages"/>
<input class="js_upFile" style="width: 20%;" type="file" name="cover" value="选择文件" id="btnimages"/>

js:

//图片上传接口
function addImages(){
    var docFile=document.getElementById("btnimages").files[0];//IE10以下不支持
    var doctorId=$("#usersnumber").val();
    var formData=new FormData();  
    formData.append("myFile",docFile); 
    formData.append("doctorId",doctorId);
    $.ajax({
        url:"http://localhost:8080/doctormanage/file/updoctorphoto.do",
        type:"post",
        data:formData,
        cache:false,
        processData:false,
        contentType:false,
        success:function(result){
            if(result.state==0){
                alert("图片上传成功");
            }else{
                alert("图片上传失败");
            }
        }
    });
};

猜你喜欢

转载自www.cnblogs.com/fanting/p/9686048.html
今日推荐