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 yiihelpersJson::encode($test); }