在前端页面导入jquery.js(需联网)
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
通用模板:
$.ajax({
url: '/index',
type: 'GET', // 'POST' ... 大小写都可以
data: { // 发送给后端的json数据
test: 1
},
success: (response) => {
console.log(response.data); // 得到后端响应
},
error: (response) => {
alert('ERROR') // 失败处理
}
})