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 :不返回数据给前端页面,但需要弹窗提示用户,强制用户进行某些操作!