Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

[solved] Trailing slash and jQuery -


Go to End


5 Posts   4781 Views

Avatar
lise

Community Member, 47 Posts

11 December 2009 at 8:48pm

Edited: 14/12/2009 10:13am

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.

Avatar
tobych

Community Member, 97 Posts

14 December 2009 at 9:41am

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

Avatar
lise

Community Member, 47 Posts

14 December 2009 at 10:13am

Edited: 14/12/2009 8:03pm

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

Avatar
tobych

Community Member, 97 Posts

14 December 2009 at 10:19am

Edited: 14/12/2009 10:20am

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

Avatar
lise

Community Member, 47 Posts

14 December 2009 at 11:03am

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