• <legend id='LKfzP'><style id='LKfzP'><dir id='LKfzP'><q id='LKfzP'></q></dir></style></legend>
    <tfoot id='LKfzP'></tfoot>

    <i id='LKfzP'><tr id='LKfzP'><dt id='LKfzP'><q id='LKfzP'><span id='LKfzP'><b id='LKfzP'><form id='LKfzP'><ins id='LKfzP'></ins><ul id='LKfzP'></ul><sub id='LKfzP'></sub></form><legend id='LKfzP'></legend><bdo id='LKfzP'><pre id='LKfzP'><center id='LKfzP'></center></pre></bdo></b><th id='LKfzP'></th></span></q></dt></tr></i><div id='LKfzP'><tfoot id='LKfzP'></tfoot><dl id='LKfzP'><fieldset id='LKfzP'></fieldset></dl></div>
      • <bdo id='LKfzP'></bdo><ul id='LKfzP'></ul>

      <small id='LKfzP'></small><noframes id='LKfzP'>

        如何在 Yii 中禁用 Ajax 请求上的 jQuery 自动加载?

        How to disable jQuery autoloading on Ajax request in Yii?(如何在 Yii 中禁用 Ajax 请求上的 jQuery 自动加载?)

        <tfoot id='vhZ2q'></tfoot>

        <small id='vhZ2q'></small><noframes id='vhZ2q'>

          <tbody id='vhZ2q'></tbody>

          <legend id='vhZ2q'><style id='vhZ2q'><dir id='vhZ2q'><q id='vhZ2q'></q></dir></style></legend>
            <bdo id='vhZ2q'></bdo><ul id='vhZ2q'></ul>
            <i id='vhZ2q'><tr id='vhZ2q'><dt id='vhZ2q'><q id='vhZ2q'><span id='vhZ2q'><b id='vhZ2q'><form id='vhZ2q'><ins id='vhZ2q'></ins><ul id='vhZ2q'></ul><sub id='vhZ2q'></sub></form><legend id='vhZ2q'></legend><bdo id='vhZ2q'><pre id='vhZ2q'><center id='vhZ2q'></center></pre></bdo></b><th id='vhZ2q'></th></span></q></dt></tr></i><div id='vhZ2q'><tfoot id='vhZ2q'></tfoot><dl id='vhZ2q'><fieldset id='vhZ2q'></fieldset></dl></div>

                  本文介绍了如何在 Yii 中禁用 Ajax 请求上的 jQuery 自动加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用以下代码生成 ajax 请求:

                  I'm using the following code to generate an ajax request:

                  echo CHtml::dropDownList('teamA', '', EnumController::getTeamOption(), array(
                          'empty' => '(Team / Single)',
                          'ajax' => array(
                              'type'=>'POST',
                              'url'=> $url,
                              'update'=>"#resultA",
                              //'data'=>"js:$('#teamA').hide().fadeIn()" 
                          )
                      )
                  );
                  

                  在我的主要布局中,我有以下内容:

                  In my main layout, I have the following:

                  <?php Yii::app()->clientScript->scriptMap=array('jquery.js'=>false);?>
                  <?php Yii::app()->clientScript->scriptMap=array('jquery.min.js'=>false);?>
                  
                  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.js"></script>
                  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
                  

                  Yii 正在从资产中加载 jQuery 副本,然后 - 另一个副本,直接来自 Google.我只想使用 Google 副本并强制 Yii 不从资产加载自己的副本.我该怎么做?

                  Yii is loading jQuery copy out of assets and then -- another copy, directly from Google. I want to use only Google copy and force Yii to not load own copy from assets. How can I do this?

                  推荐答案

                  在 Yii 中,你永远不应该在主布局中硬编码任何 javascript 信息.

                  In Yii you should never hardcode any javascript information in the main layout.

                  Yii 可以确定是否已包含客户端脚本 (javascript),但对于核心脚本(如 jquery 或 jqueryui),您必须在配置文件中修改这些包.

                  Yii can determine if a client script (javascript) was already included, but for core scripts (like jquery or jqueryui) you have to modify those packages in your config file.

                  打开main.php配置文件,在CClientScript组件中添加你需要的所有js包(你应该把它添加到components),像这样:

                  Open the main.php configuration file and add all the js packages you need within the CClientScript component (you should add it inside components), like this:

                  'clientScript'=>array(
                    'packages'=>array(
                      'jquery'=>array(
                        'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8/',
                        'js'=>array('jquery.min.js'),
                        'coreScriptPosition'=>CClientScript::POS_HEAD
                      ),
                      'jquery.ui'=>array(
                        'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jqueryui/1.8/',
                        'js'=>array('jquery-ui.min.js'),
                        'depends'=>array('jquery'),
                        'coreScriptPosition'=>CClientScript::POS_BEGIN
                      )
                    ),
                  ),
                  

                  然后,每次需要 jquery 时,只需在代码前添加:

                  Then, every time you need jquery just add this before your code:

                  $cs = Yii::app()->getClientScript();
                  $cs->registerCoreScript('jquery');
                  

                  Yii 将只包含一次 jquery(或任何其他脚本),即使您在代码中多次调用它.

                  Yii will then include jquery (or any other script) only once, even if you call it several times in your code.

                  这篇关于如何在 Yii 中禁用 Ajax 请求上的 jQuery 自动加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                    <tfoot id='ZGq7g'></tfoot>

                      <bdo id='ZGq7g'></bdo><ul id='ZGq7g'></ul>

                        <i id='ZGq7g'><tr id='ZGq7g'><dt id='ZGq7g'><q id='ZGq7g'><span id='ZGq7g'><b id='ZGq7g'><form id='ZGq7g'><ins id='ZGq7g'></ins><ul id='ZGq7g'></ul><sub id='ZGq7g'></sub></form><legend id='ZGq7g'></legend><bdo id='ZGq7g'><pre id='ZGq7g'><center id='ZGq7g'></center></pre></bdo></b><th id='ZGq7g'></th></span></q></dt></tr></i><div id='ZGq7g'><tfoot id='ZGq7g'></tfoot><dl id='ZGq7g'><fieldset id='ZGq7g'></fieldset></dl></div>
                        <legend id='ZGq7g'><style id='ZGq7g'><dir id='ZGq7g'><q id='ZGq7g'></q></dir></style></legend>
                          <tbody id='ZGq7g'></tbody>
                          • <small id='ZGq7g'></small><noframes id='ZGq7g'>