yii2 输出json的方法

public function actionAjax()
{
    if(isset(Yii::$app->request->post('test'))){
        $test = "Ajax Worked!";
        // do your query stuff here
    }else{
        $test = "Ajax failed";
        // do your query stuff here
    }

    // return Json    
    return \yii\helpers\Json::encode($test);
}

 

posted @ 2017-03-31 11:02  侠岚之弋痕夕  阅读(2777)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!