Files
xiezheng_h5/笔记.md
2024-11-30 22:40:02 +08:00

27 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ajax 请求一般会有三个状态码
1 ajax 提供的 readyState 0 1 2 3 4
2 http 提供的 status 200 404 302 502....
readyState == 4 && status == 200
客户端和服务器都在线,请求可以正常的收发
3 后端自己定义的 状态码
作用:对我们的业务功能操作进行快速判断
code 取值有:
200表示成功获取到data数据
100表示操作成功但是不需要返回data数据给前端所以data == null只是返回一个操作状态的文字提示例如用户修改删除
404表示没有获取到data数据所以返回错误的具体信息。
500表示系统级别的错误一般后端程序出错缺少token或者用户不存在等
403表示token失效需要前端重定向登录页面重新登录
前端根据 code 的取值的不同需要自行在拦截器里面处理各种情况,一般建议如下处理:
code == 200 返回data中的数据给前端页面使用
code == 100 不返回数据给前端页面不需要toast提示用户
code == 404 不返回数据给前端页面但需要toast提示用户
code == 500 :不返回数据给前端页面,但需要弹窗提示用户!
code == 403 :不返回数据给前端页面,但需要弹窗提示用户,强制用户进行某些操作!