LeePC
我们努力不是为了成为金字塔上的人,我们努力是为了超越自己,使得自己变的更好。

本想用YII2自带的JS,可是用着效果不好,想从新加载,找了好多终于实现啦!还有ajax(json)传值接值!

首先直接了当的就把YII2自带的js去掉!

把下面代码加入到/config/main.php文件'components'=>[]里面,可以禁掉CSS和JS

 1 'components' => [
 2     .............
 3     //不加载YII2自带JS以及CSS
 4         'assetManager'=>[
 5             'bundles'=>[
 6               'yii\bootstrap\BootstrapAsset'=>[
 7                    'css'=>[],
 8               ],
 9               'yii\web\JqueryAsset'=>[
10                    'js'=>[],
11                ],
12               'yii\bootstrap\BootstrapPluginAsset'=>[
13                    'js'=>[]
14                ]
15            ]
16        ],
17 ]    

加载自己的就是把JS文件放在WEB下,然后设置好路径就OK

 

<script type="text/javascript" src="style/js/jquery-1.7.2.min.js"></script>

 

 

 

ajax传值接值:

  视图层文件:/wiew/index.php


    function search(id){
        //alert(id);
        $.ajax({
            type:'post',
            url : "?r=site/ajax",
        //json一样的只是那么格式变成json格式就OK
            //dataType:'json',
            data:"id="+id,
            success:function(msg){
                alert(msg);
            }
        })

 视图层文件:/contollers/SiteController.php

    

1 //搜索方法
2     public function actionAjax(){
3         $id=Yii::$app->request->post('id');
4    // return json_encode($id);
5         return $id;
6     }

 

 

 


posted on 2017-04-24 14:17  三哥~!  阅读(609)  评论(0编辑  收藏  举报