yii2使用ajax返回json的实现方法

原创 2017-01-05 13:24:56 251
摘要:本文实例讲述了yii2使用ajax返回json的实现方法。分享给大家供大家参考,具体如下:public function actionAjax() {   if(isset(Yii::$app->request->post('test'))){     $test = &

本文实例讲述了yii2使用ajax返回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);
}

更多关于yii2使用ajax返回json的实现方法实例请关注PHP中文网(www.php.cn)其他文章!

发布手记

热门词条