//当 code == 200 时候 是成功 data 中是要用的数据
//当 code != 200 时候 msg 中是错误的信息,用于前端的错误提示
{
"code": 200,
"data": {},
"msg": "xxxxxxxxxxx",
}
接口尽量体积小,没必要将字段删减到最小,但最好不要上 100k
请求接口,当前页码 key——page,以 1 开始
每页条数 key-rows,一般是 10,返回格式:
{
code: 200,
data: {
items: [
{ id: 1, name: 'xxx' },
{ id: 2, name: 'xxx' },
],
page: { curPage: 1, pageSize: 10, totalPage: 2, totalRow: 20 },
},
msg: 'xxxxxxxxxx',
};
默认需要将新添加的 json 对象返回,用于不刷新界面继续操作
后台返回接口
// ajax: httpstatus 400
{
errCode: '9000',
errMsg: 'http://uc.lecloud.com/login.do?backUrl=http://saas.lecloud.com',
errShowMsg: '用户未登录',
};
前台控制— jquery ajax 统一过滤
// 判断控制浏览器跳转,http code 为 400 时,判断 errcode 值
$(document).ajaxError(function (event, request, settings, thrownError) {
console.log(request);
try {
if (request.status == 400) {
var responseJSON = JSON.parse(request.responseText);
if (responseJSON.errCode == 90000) {
top.window.location.href = responseJSON.errMsg;
}
}
} catch (e) {}
});

