首页›MVC 核心›JSON 方法族
JSON 方法族
jsonReturn / jsonpReturn 与 arrReturn 响应数组约定
本页内容
- 方法清单
- arrReturn 组装规则
- 状态码约定(配合前端 formCallback)
方法清单
| 方法 | 签名 | 行为 |
|---|---|---|
jsonReturn | jsonReturn($config,$message=NULL,$data=[]) | setLayout(false) + Content-type: application/json;$config 为 int/string 时经 arrReturn 组装,返回 JSON 字符串 |
jsonpReturn | jsonpReturn($config,$message=NULL,$data=[]) | JSONP 跨域:读取 post.callback(默认 handleResponse),返回 callback(json) |
arrReturn 组装规则
| status | 结果 |
|---|---|
0 | {status:0, message:"..."}(无 data 字段) |
9 | {status:9, message:"...", url:data}(第三参进 url) |
| 其它非 0 | {status:N, message:"...", data:data} |
状态码约定(配合前端 formCallback)
| status | 含义 | 前端行为 |
|---|---|---|
| 0 | 失败 | toast 错误提示 |
| 1 | 成功(仅提示) | toast 成功提示 |
| 2 | 强提示 | alert 弹窗 |
| 3 | 跨窗口消息 | postMessage |
| 4 | 刷新当前页 | location.reload |
| 5 | 返回上一页 | history.back |
| 6 | 关闭弹窗 | 关闭当前弹窗+父页提示 |
| 7 | 弹窗内提交成功 | 关闭弹窗+刷新父页 |
| 8 | 替换地址 | location.replace |
| 9 | 跳转 | 跳转到 url 字段 |
典型用法
return $this->jsonReturn(1, "ok", $data); // 成功
return $this->jsonReturn(0, "参数错误"); // 失败
return $this->jsonReturn(7, "保存成功"); // 弹窗提交成功(前端自动关窗刷新父页)
return $this->jsonReturn(9, "请登录", url("Login")); // 跳转
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页