使用AJAX实现上传文件
<form id="uploadForm" method="post" enctype="multipart/form-data"> <label >上传电子书</label> <input type="file" name="file" > <button id="upload" type="button" name="button" >上传</button> </form>
$("#upload").click(function () { var formData = new FormData($('#uploadForm')[0]); $.ajax({ type: 'post', url: "https://****:8443/fileUpload", //上传文件的请求路径必须是绝对路劲 data: formData, cache: false, processData: false, contentType: false, }).success(function (data) { console.log(data); alert("上传成功"+data); filename=data; }).error(function () { alert("上传失败"); }); });