本文实例讲述了yii2使用ajax返回json的实现方法。分享给大家供大家参考,具体如下:
public function actionAjax(){ if(isset(Yii::$app->request->post('test'))){ $test = "Ajax Worked!"; // do your query stuff here }else{ <strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码*网/</strong><strong>搞gaodaima代码</strong> $test = "Ajax failed"; // do your query stuff here } // return Json return \yii\helpers\Json::encode($test);}
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。