Valid jQuery scripts not loading in production mode

佐手、 提交于 2019-12-13 03:55:04

问题


Having some troubles with my site in production mode. Getting some errors from the jQuery scripts so it's not loading. Thought jQuery.noConflict(); could solve it, but it failed me! Been trying so many things now so I'm open for any suggestions to solutions or debugging.

Heres my errors:

Uncaught controls.js requires including script.aculo.us' effects.js library
/#about:30Uncaught TypeError: Object [object Object] has no method 'cycle'
/#about:12Uncaught TypeError: Object [object Object] has no method 'cycle'

The one who solves it gets a gold star! Thank you ;(


回答1:


You'll need to fix the first error before tackling subsequent errors (since they may come from a cascading failure). According your your uncaught exception, you have a script called "controls.js" that requires the script.aculo.us library to be loaded on the page in order to work. Download the library from here Script.aculo.us put it into your web directory, and include it BEFORE controls.js loads:

<script type="text/javascript" src="/location/to/scriptaculous.js"></script>



回答2:


A Gold Star ? Ok I had a similar problem. Your problem is not jQuery.noConflict(); neither is it prototype js but rather that you did not add everything there is to to the noconflict

1 - Fist of all align every other librairie that does not use jquery ex:

<script src="js/scriptaculous/lib/prototype.js" type="text/javascript"></script>

<script src="js/scriptaculous/src/scriptaculous.js" type="text/javascript"></script>

 <script language="javascript" src="js/protoplasm/protoplasm.js"></script>

 <script>
        Protoplasm.use('rte').transform('textarea.richeditor');
</script>

2 - After that insert your jquery file and directly followed up with noconflict before any other library or code that uses jquery

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

    $.noConflict();

    </script>

3 - And MOST IMPORTANTLY and this is where you are missing the point Open each and every other javascript code you have as js that uses jquery like Bootstrap.min.js or app.js and if you find jquery inside, then put on top of the code, at the very begin of the file (ex at the begining of bootstrap.min.js) the following code

jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.


///////////////////////////////////////////////////////////////////////////////

4- At the very end of the code (ex at the end of bootstrap.min.js) put the following code

///////////////////////////////////////////////////////////////////////////////

});

5 - Put also every other code using jquery in your page between another

 jQuery( document ).ready(function( $ ) {
    // Code that uses jQuery's $ can follow here.


    ///////////////////////////////////////////////////////////////////////////////


 ///////////////////////////////////////////////////////////////////////////////

    });

As you can see jquery noconflict alone is not enough. You really have to add those codes everywhere jquery is being used even in external file if you do not want any interference

You may face some few error in controls.js with firebug but all your codes will work. Even when you remove control.js, as long as scriptaculous.js is on your page, Firebug will always give you and error like TypeError: this.element is null controls.js but all your code will be working perfectly.

Please, do not forget the Gold star. Thanks



来源:https://stackoverflow.com/questions/9253977/valid-jquery-scripts-not-loading-in-production-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!