Ajax
Axios中文网(POST & GET) json-server官网
AJAX 简介
AJAX全称为Asynchronous JavaScript And XML,就是异步的JS和XML。
通过AJAX可以在浏览器中向服务器发送异步请求,最大的优势:无刷新获取数据。
AJAX不是新的编程语言,而是一种将现有的标准组合在一起使用的新方式。
restFul访问方式:
- get是查询
- post是添加
- put是全体修改
- patch是局部修改
- delete是删除
- options预检请求
Fetch:(一般用axios)
fetch(url).then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
}).catch(function(e) {
console.log("Oops, error");
});
var url ='https://example.com/profile';
var data = {username:'example'};
fetch(url, {
method:'POST',// or 'PUT'
body: JSON.stringify(data),// data can be `string` or {object}!
headers:new Headers({
'Content-Type':'application/json'
})
}).then(res => res.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
GET:
- 访问的是db.json⽂件下的所有内容;
http://localhost:3000/db
- 模拟接⼝参数可筛选该⽬录下内容;
http://localhost:3000/layoutList?categoryName=
- 分⻚查询 参数为 start, _end, _limit,并可添加其它参数筛选条件;
- 排序参数为sort, order ;
- 操作符 _gte, _lte, _ne, _like ;
_gte⼤于, lte⼩于, _ne⾮, _like模糊查询 ;
- q全局搜索(模糊查询);
- 其他查询方式: