正文
ThinkPHP的ajaxReturn方法的使用
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
ThinkPHP后端的代码如下: public function testAjax(){
$this->ajaxReturn(array('name'=>'z','age'=>18), 'this-is-info', 1);
} 说明:
ajaxReturn的三个参数分别为:
ajaxReturn($data, $info, $status);
$data,返回的主要内容就放在$data中;
$info,一句话表示操作情况;
$status,操作状态,一般用0(失败)和1(成功)来表示。如果操作失败,可以在$info中简单说明原因。如果操作成功,必要是在$data中返回关联的数据。 前端输出的结果如下:
{"data":{"name":"z","age":18},"info":"this-is-info","status":1} 可以使用$.getJSON()来获取并处理返回的数据。