@H_403_0@本文实例讲述了yii2控制器Controller Ajax操作的方法。分享给大家供大家参考,具体如下:
<div class="jb51code">
<pre class="brush:php;">
public function actionSample()
{
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
$searchname= explode(":",$data['searchname']);
$searchby= explode(":",$data['searchby']);
$searchname= $searchname[0];
$searchby= $searchby[0];
$search = // your logic;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return [
'search' => $search,'code' => 100,];
}
}