$('#btnupload').on('click', function () { var fd = new FormData(); var reportid = window.location.href.split('=')[1]; fd.append("report_id", reportid); fd.append("txtfile", $("#txtfile").get(0).files[0]); $.ajax({ url: "http://localhost:8081/api/file/PostFile", type: "POST", processData: false, contentType: false, headers: { "Authorization": "Basic " + btoa("admin" + ":" + "698d51a19d8a121ce581499d7b701668") }, data: fd, success: function (d) { layer.msg('上传成功', { time: 1000 }, function () { window.location.href = "@Url.Action("Index", "ReportList")"; }); } }); });
<input name="txtfile" id="txtfile" type="file" /><br /> <input name="btnupload" class='btn btn-primary fa fa-save' id="btnupload" type="button" value="上传" />