ajax文件上传

来源:互联网 发布:手动网络 编辑:程序博客网 时间:2024/06/15 21:24
<button class="_box btn btn-primary">批量导入</button><div style="display: none">   <input type="file" onchange="OpinionInfoDlg.fileUpChange(this.value)"  name="_f" id="_f"/></div>
$("._box").click(function () {    return $("#_f").click();});OpinionInfoDlg.fileUpChange=function(filePath) {    if (filePath.indexOf("xls") != -1) {        var fd = new FormData();        fd.append("file", $("#_f").get(0).files[0]);        $.ajax({            url: Feng.ctxPath + "/opinionExcel",            type: "POST",            processData: false,            contentType: false,            data: fd,            success: function(d) {                console.log(d);            }        });    }else{        Feng.info("请选择正确的文件格式!");    }}