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.

General Questions /

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

JQuery conflict: unrecognized expression [ SOLVED ]


Reply


7 Posts   4957 Views

Avatar
xpyx

Community Member, 5 Posts

19 November 2011 at 10:42am

I have a page which is breaking on this function:

            $(options.navigation).click(function() {
               panel = $($(this).attr('href'));
               $(window)._scrollable().stop();
               $.scrollTo(panel, {
                  duration: 500,
                  easing: 'swing'
               });

HTML: <a href="#panel1" class="navigation" title="Panel 1">1</a>

It gives me "Syntax error, unrecognized expression: /" clicking on any navigation item, from the line "panel = $($(this).attr('href'));"

If I have the exact same HTML page outside of Silverstripe it works perfectly.

If I copy the file to say, http://localhost/dev.html and run this inside SilverStripe it's also fine.

But if I run it at http://localhost/dev/ it gives me the Syntax error again. Is is something to do with mod_rewrite? The script even works fine when I'm not running it via a server (just directly in the browser).

Any theories about what's going on here? I've been stuck on this bug for a couple of hours now, would be wonderful to know if there is a fix.

Avatar
danzzz

Community Member, 175 Posts

20 November 2011 at 1:46am

try this in init() of Page_Controller

Requirements::set_write_js_to_body(false);

Avatar
xpyx

Community Member, 5 Posts

20 November 2011 at 8:08am

Thanks, no luck I'm afraid. I've made sure all the javascript includes are not minified. Would love any other input.

Avatar
simon_w

Forum Moderator, 474 Posts

20 November 2011 at 8:58am

SilverStripe is rewriting the link so that it includes the current URL so that the anchor link actually works. You can usually get around this by using single quotes around the href attribute instead of double quotes.

Avatar
xpyx

Community Member, 5 Posts

20 November 2011 at 9:00am

Thank, I have single quotes: $($(this).attr('href'));

Any other thoughts?

Avatar
simon_w

Forum Moderator, 474 Posts

20 November 2011 at 9:01am

Not in the JavaScript, in the template.

Avatar
xpyx

Community Member, 5 Posts

20 November 2011 at 9:03am

Awesome, fixed! Thank you so much.

Changed:<a href="#panel1" class="navigation" title="Panel 1">1</a>

To: <a href='#panel1' class='navigation' title='Panel 1'>1</a>

Thanks, that's really great to know.