后端用的是springboot
使用jquery封装了三种常用的请求方式
const appendUrl = function (suffix) {
return "http://localhost:8011" + suffix;
};
//form get
const get = function (url, body, suc) {
$.ajax({
url: appendUrl(url),
data: body,
success: suc
})
};
//json post
const jsonPost = function (url, body, suc) {
$.ajax({
url: appendUrl(url),
type: "post",
headers: {
"content-type":"application/json;charset=UTF-8"
},
data: JSON.stringify(body),
success: suc
})
};
//form post
const formPost = function (url, body, suc) {
$.ajax({
url: appendUrl(url),
type: "post",
data: body,
success: suc
})
};
get对应后端的@GetMapping
formPost对应后端的@PostMapping
jsonPost对应后端@PostMapping以及参数接收用了@RequestBody
调用方法
res就是后端返回的restful api返回体
{index: now}就是请求携带的body
如果不需要就放{}
这个url是被封装过拼接起来的 所以只需要除开前面相同部分的路径即可