首页MVC 核心JSON 方法族
JSON 方法族
jsonReturn / jsonpReturn 与 arrReturn 响应数组约定
本页内容
  1. 方法清单
  2. arrReturn 组装规则
  3. 状态码约定(配合前端 formCallback)

方法清单

方法签名行为
jsonReturnjsonReturn($config,$message=NULL,$data=[])setLayout(false) + Content-type: application/json;$config 为 int/string 时经 arrReturn 组装,返回 JSON 字符串
jsonpReturnjsonpReturn($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 · 返回首页