1,jquery和jquery.form.min.js 在各自官网下载均可
<html>
<head>
<title>文件上传</title>
<script src="jquery-3.3.1.min.js" type="text/javascript"></script>
<script src="jquery.form.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnsubmit").click(function () {
$("#form1").ajaxSubmit({
success: function (data) {
alert(data.url);
},
error: function (error) { alert(error); },
url: 'http://www.baidu.com/enterprise/employees/export', /*设置post提交到的页面*/
type: "post", /*设置表单以post方法提交*/
dataType: "json", /*设置返回值类型为文本*/
xhrFields: {
withCredentials: true
},
crossDomain: true
});
});
});
</script>
</head>
<body>
<h2>文件上传</h2>
<form enctype="multipart/form-data" id="form1">
<input type="file" name="importData" />
<input type="button" id="btnsubmit" value=" 上 传 " />
</form>
</body>
</html>