【问题标题】:Yii2 - jQuery working only on remote serverYii2 - jQuery 仅在远程服务器上工作
【发布时间】:2015-11-13 21:10:16
【问题描述】:

按照@AliMasudianPour 的topic 说明,我能够让Jquery 在我的远程服务器 上的开发/生产环境中正常工作。但是,在我的 本地服务器 上运行 Mamp。 Jquery 坚持不工作。我不断收到错误:

$ 未定义
jQuery 未定义
yii 未定义
无法读取未定义的属性“fn”

我比较了本地和远程 CommonFrontend 目录中的所有 AppAssetsConf 行安装。

我可能跳过了一些重要的步骤。有人可以给我一些提示吗?

我的代码中的一些 sn-ps:

前端/assets/AppAsset.php

<php
namespace frontend\assets;
use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/main.css',
    ];
    public $js = [
        'js/jquery-1.11.3.min.js',
    ];
    public $jsOptions = [
        'position' => \yii\web\View::POS_HEAD
    ];
    public $depends = [
    ];
}

在前端/config/main.php

内部组件:

'assetManager' => [
            'bundles' => [
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'js'=>[]
                ],
                'yii\bootstrap\BootstrapAsset' => [
                    'css' => []
                ],
                'yii\web\JqueryAsset' => [
                    'sourcePath' => null,
                    'js'=>[]
                ],
            ],
        ],

关于视图中的布局:

use frontend\assets\AppAsset;
AppAsset::register($this);

顺便说一句,它适用于其他 js 脚本,但不适用于 jquery!

【问题讨论】:

  • 您确定,您的路径正确吗?尝试直接访问您的 jquery 文件
  • 是的,我用其他的 js 脚本试过了,效果很好。
  • 您是否尝试过查看源代码并点击了这些资产?

标签: php jquery yii2


【解决方案1】:

我摆脱了这两段代码,现在一切正常。

public $js = [
    'js/jquery-1.11.3.min.js',
];




'bundles' => [
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'js'=>[]
                ],
                'yii\bootstrap\BootstrapAsset' => [
                    'css' => []
                ],
                'yii\web\JqueryAsset' => [
                    'sourcePath' => null,
                    'js'=>[]
                ],
            ],

并包含

public $depends = [
   'yii\web\YiiAsset',
];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2015-06-19
    • 1970-01-01
    • 2015-12-08
    • 2022-01-05
    • 1970-01-01
    • 2013-03-03
    相关资源
    最近更新 更多