<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
</head>
<body>
<form id="form">
<input type="text" name="username" id="username" value="" />
<input type="password" name="password" id="password" value="" />
<input type="button" name="login" id="login" value="登录" onclick="submit_form()" />
</form>
<script>
function submit_form() {
console.log($("#form").serialize());
$.ajax({
url: "http://localhost:8080/web/AjaxDemo", //请求的url地址
dataType: "json", //返回格式为json
async: true, //请求是否异步,默认为异步,这也是ajax重要特性
data: {
"username": "value"
}, //参数值
type: "POST", //请求方式 get 或者post
success: function(req) {
//请求成功时处理
},
error: function() {
//请求出错处理
}
});
}
</script>
</body>
</html>