1、先引入Jquery的包,在html文件中利用script标签引入Jq包
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
2、页面部分请求接口 $.ajax
$.ajax({
url: 'http://localhost:8000/api/xxx/xxxx', // 请求地址
type: 'post', // 请求方式
data: '', //携带到后端的参数
contentType: 'application/x-www-form-urlencoded', // 传参格式(默认为表单) json为application/json
dataType: 'json', //期望后端返回的数据类型
success: function (res) {
console.log('res', res);
}, // 成功的回调函数 res就是后端响应回来的数据
error: function(err) {
console.log('err', err);
} // 失败的回调函数
})