|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
yii2控制器Controller Action ajax使用方法
- 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,
- ];
- }
- }
复制代码 模板调用- $.ajax({
- url: '<?php echo Yii::$app->request->baseUrl. '/supermarkets/sample' ?>',
- type: 'post',
- data: {searchname: $("#searchname").val() , searchby:$("#searchby").val()},
- success: function (data) {
- console.log(data.search);
- }
- });
复制代码 |
|