纯ajax上传文件

来源:互联网 发布:单片机初始化程序8255 编辑:程序博客网 时间:2024/05/17 04:58

无需用到插件,直接ajax就可以上传文件,请看代码

<input onchange="uploadFile(this);" type="file" name="files"/>
function uploadFile(item){    var _this = $(item);    var fileObj = _this.get(0).files;     if(fileObj.length == 0){        return;    }    //这个是关键    var formdata = new FormData();    formdata.append("files", fileObj[0]);     $.ajax({        type:"post",        url:"../upload/uploadFile.do",        data:formdata,        dataType:"json",//      async:false,        cache : false,         contentType : false,         processData : false,         success:function(result){        },        error:function(result){        }    });}





0 0