摘要:本文实例讲述了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)其他文章!