html5上传
<!DOCTYPE html>
<html>
<head>
<title>Html5 Ajax 上传文件</title>
<script type="text/javascript">
function UpladFile() {
console.log(11)
var fileObj = document.getElementById("file").files[0]; // 获取文件对象
var FileController = "http://localhost:8080/Javar-fast/oss/files/upload"; // 接收上传文件的后台地址
// FormData 对象
var form = new FormData();
form.append("author", "chenji"); // 可以增加表单数据
form.append("file", fileObj); // 文件对象
// XMLHttpRequest 对象
var xhr = new XMLHttpRequest();
xhr.open("post", FileController, true);
xhr.onload = function () {
alert("上传完成!");
};
xhr.send(form);
}
</script>
</head>
<body>
<input type="file" id="file" name="myfile" />
<input type="button" onclick="UpladFile()" value="上传" />
<br>
<br>
<br>
<br>
<br>
<br>
<br>
https://www.172u.cn/ 一起遨游网提供
</body>
</html>
最后更新于 2022-06-25 02:56:46 并被添加「」标签,已有 1047 位网友阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
此处评论已关闭