jq的get,post请求的演示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>标题</h1>
<h2>名称</h2>
<h3>皮肤</h3>
<script src="./lib/jquery.min.js"></script>
<script>
$(function () {
$.get(
"http://127.0.0.1:3001/getHero",
function (res) {
console.log(res);
$("h1").text(res.data.title);
$("h2").text(res.data.cname);
$("h3").text(res.data.skin_name);
}
)
})
$("#heroSubmit").click(function () {
const name = $("#name").val().trim();
const gender = $("#gender").val();
const img = "";
$.post("http://127.0.0.1:3001/addHero", { name, gender, img }, function (res) {
console.log(res);
})
</script>
</body>
</html>