html代码:
<div class="form-group">
<div class="col-sm-10" style="margin-left: 650px;margin-top: 100px">
选择文件上传:<input type="file" id="file" name="file" @change="upload"
style="margin-left: 50px;margin-top: -200px"></input>
</div>
</div>
js代码:
function upload() {
var form = new FormData();
var file = document.getElementById("file").files[0];
form.append("file", file);
$.ajax({
url: "web/inportExcel",
type: "POST",
data: form,
cache: false,
async: false,
processData: false,
contentType: false,
dataType: "json",
success: function (r) {
}
});
}
html代码表单也可以使用button 绑定onclick方法去调用js 大同小异