<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript" src="/js/jquery-1.8.3.js" ></script>
<script type="text/javascript">
function UpladFile() {
var fileObj = document.getElementById("file").files[0]; // 获取文件对象
var FileController = "http://192.168.23.174:8080/WeiKe/fileUpload?action=DruqwPmF1keVPn1s15Cy&userId=BC1000037589"; // 接收上传文件的后台地址
// FormData 对象
var form = new FormData();
form.append("author", "hooyes"); // 可以增加表单数据
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" οnclick="UpladFile()" value="上传" />
</body>
</html>
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript" src="/js/jquery-1.8.3.js" ></script>
<script type="text/javascript">
function UpladFile() {
var fileObj = document.getElementById("file").files[0]; // 获取文件对象
var FileController = "http://192.168.23.174:8080/WeiKe/fileUpload?action=DruqwPmF1keVPn1s15Cy&userId=BC1000037589"; // 接收上传文件的后台地址
// FormData 对象
var form = new FormData();
form.append("author", "hooyes"); // 可以增加表单数据
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" οnclick="UpladFile()" value="上传" />
</body>
</html>