Action::ajaxReturn PHP Method

ajaxReturn() protected method

Ajax方式返回数据到客户端
protected ajaxReturn ( mixed $data, String $info = '', boolean $status = 1, $type = 'JSON' )
$data mixed 要返回的数据
$info String 提示信息
$status boolean 返回状态
    protected function ajaxReturn($data, $info = '', $status = 1, $type = 'JSON')
    {
        // 保证AJAX返回后也能保存知识
        if (C('LOG_RECORD')) {
            Log::save();
        }
        $result = array();
        $result['status'] = $status;
        $result['info'] = $info;
        $result['data'] = $data;
        if (empty($type)) {
            $type = C('DEFAULT_AJAX_RETURN');
        }
        if (strtoupper($type) == 'JSON') {
            // 返回JSON数据格式到客户端 包含状态信息
            header('Content-Type:application/json; charset=utf-8');
            exit(json_encode($result));
        } elseif (strtoupper($type) == 'XML') {
            // 返回xml格式数据
            header('Content-Type:text/xml; charset=utf-8');
            exit(xml_encode($result));
        } elseif (strtoupper($type) == 'EVAL') {
            // 返回可执行的js脚本
            header('Content-Type:text/html; charset=utf-8');
            exit($data);
        } else {
            // TODO 增加其它格式
        }
    }

Usage Example

コード例 #1
0
 protected function ajaxReturn($status = 1, $msg = '', $data = '', $dialog = '')
 {
     parent::ajaxReturn(array('status' => $status, 'msg' => $msg, 'data' => $data, 'dialog' => $dialog));
 }
All Usage Examples Of Action::ajaxReturn