Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » JQuery does not load

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2705 Views
  • Krigu
    Avatar
    Community Member
    7 Posts

    JQuery does not load Link to this post

    Hi

    I'm trying to load a custom jQuery script from one of my templates. Heres my code.

    Company.js

    (function($) {
       $(document).ready(function() {
    alert('jQuery is loaded!');
       })
    })(jQuery);

    In the ss-file I have:

    <% require javascript(mysite/javascript/Company.js) %>

    The script is loaded, but it does not execute the alert. Do i need to include the jQuery library or something? I diden't find anything in the docs (http://doc.silverstripe.org/2.4:javascript)

    I'm using SS 2.4 rc2.

    Thanks a lot
    Chris

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: JQuery does not load Link to this post

    Yes you need to include jquery. Load it before Company.js

    <% require javascript(mysite/javascript/jquery-1.4.2.min.js) %>
    <% require javascript(mysite/javascript/Company.js) %>

    Make sure you download jquery and put it in your mysite/javascript folder:
    http://code.jquery.com/jquery-1.4.2.min.js

  • Krigu
    Avatar
    Community Member
    7 Posts

    Re: JQuery does not load Link to this post

    Thank you for your answer ampedup.

    My thought was, that because of the fact, that jQuery is now the offical JS libary in the 2.4 release, I don't have to extra download and include jquery. Is there no possibility to use the SS jquery library?

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: JQuery does not load Link to this post

    You could, but you would still need to call require javascript([jquerylocation]) to include it.

    I personally prefer to download jquery and include that, or include the google api jquery: https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

    But that's me, I don't know what the consensus of the community is.

    2705 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.