<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>上传文件</title>
</head>
<body>
<!-- <form action="http://192.168.1.199:10088/api/other/apache" method="post"enctype="multipart/form-data"> -->
<input type="file" name="fileName" onchange="uploadChange()" id="fileToUpload">
<button type="submit" onclick="uploadfile()">提交</button>
<!-- </form> -->
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
function uploadChange() {
var file = document.getElementById('fileToUpload').files[0];
console.log(file);
}
function uploadfile() {
var file = document.getElementById('fileToUpload').files[0];
var formdata=new FormData();
formdata.append("file",file);
// var a={
// file:file
// }
$.ajax({
url:'http://192.168.1.199:10088/api/other/apache',
type:'POST',
data:formdata,
processData: false,
contentType: false,
success:function(res){
console.log(res);
},
error:function(){
}
});
}
</script>
</body>
</html>
[JavaScript]FormData上传文件
最新推荐文章于 2024-08-12 09:54:37 发布