Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [solved] Trailing slash and jQuery -

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: 2839 Views
  • lise
    Avatar
    Community Member
    47 Posts

    [solved] Trailing slash and jQuery - Link to this post

    I am still struggling to have jQuery work properly on my 2.3.3 installation. I have finally narrowed down the problem to a question
    of "trailing slash" ("/") at the end of the URLs .

    If I use the url :
    http://www.mysite.com/ag

    it works fine. jQuery is defined and I can animate my page ( tabs animation)

    But if I try to access the page as :
    http://www.mysite.com/ag/ or
    http://www.mysite.com/ag/?flush=1

    jQuery is not defined (of course if I remove the trailing slash and reload , it works perfectly)

    I am totally puzzled here ...
    FYI: to relsove another problem with local anchors I have added
    SSViewer::setOption('rewriteHashlinks', false);
    to my config file, following the forum entry : http://www.silverstripe.org/general-questions/show/252254

    It seems that a lot of you are able to use jQuery so ...what am I missing??
    Any pointer , help, ..etc ..will be highly appreciated as I am simply running out of ideas...

    Thanks.

  • tobych
    Avatar
    Community Member
    97 Posts

    Re: [solved] Trailing slash and jQuery - Link to this post

    I'm no JQuery expert, but I imagine it's nothing to do with JQuery as such.

    1. Aren't pages without the trailing slash redirecting to a page with a slash anyway?

    2. Also, how are you making sure the JQuery library gets included in the page?

    You've something like this in a the relevant page controller's init(), right?

    Requirements::javascript("mysite/javascript/lib/jquery-1.3.2.js");

    Toby

  • lise
    Avatar
    Community Member
    47 Posts

    Re: [solved] Trailing slash and jQuery - Link to this post

    Tobych: Thank you for your reply. The problem was actually due to the way our code looks for external resources (we use the
    Google Ajax Librairies API). I did not write the patch for this. I know it had to do with the way we access jQuery :
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js" type="text/javascript"></script>

    The line above works for us.

    For your info: I have had several (other) problems when using "Requirements" for my javascript files and it has been suggested by other members here to include js librairies directly in the template files. I run the 2.3.3 version of SS . Iy might also be that the problem did not exist in previous versions.
    Regards.
    Lise

  • tobych
    Avatar
    Community Member
    97 Posts

    Re: [solved] Trailing slash and jQuery - Link to this post

    Glad you solved the problem. Yes, including Javascript libraries can be a pain with SilverStripe, because a) by default the javascript is included at the end of <body> (for reasons of efficiency, as I understand it), and b) because it's not possible to choose per call to Requirements::javascript() whether the script should be included in the head or at the bottom of the body.

    Trouble is though, Requirements::javascript() is pretty damn handy.

    In a recent project I had success by throwing efficiency to the wind and calling this in my Page_Controller::init():

    Requirements::set_write_js_to_body(false);

    Toby

  • lise
    Avatar
    Community Member
    47 Posts

    Re: [solved] Trailing slash and jQuery - Link to this post

    Thanks for the tip! I will try it. (I agree that a "working" Requirements is quite convenient! )

    2839 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.