描述:通过前台html页面,发送请求,获取后台的数据
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<button id="get">登录测试</button>
<script>
$(function () {
$("#get").on('click',function () {
$.get('http://localhost:8082/test/h1',function (res) {
alert(res);
})
})
})
</script>
</body>
</html>
Java
@RestController
@RequestMapping("/test")
public class HelloController {
@GetMapping("/h1")
public String h1(){
return "登录成功";
}
}
涉及到的
使用到的有HTML、jQuery、Java、JavaScript、ajax
通过点击按钮,向后台发送请求,获取到数据,并展示到页面
一起交流,一起学习,向前,向前,向前!!!