Can only set cookies using javascript when logged in
Permalink
Can anyone give me any tips on how I can set and retrieve a cookie using javascript?
If I'm logged in I can do it with $.cookie('last', 'model');
But that doesn't work if the user isn't logged it.
I assumed it was because I needed to include jquery and jqueryui using registerAssets in page_theme.php, but no joy.
What am I missing?
If I'm logged in I can do it with $.cookie('last', 'model');
But that doesn't work if the user isn't logged it.
I assumed it was because I needed to include jquery and jqueryui using registerAssets in page_theme.php, but no joy.
What am I missing?
You need to include jquery-cookie.js
Yeah. I tried that, too. It's not in the asset list, so I tried including it this way in my page header:
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/js/jquery-cookie.js"></script>
I had no luck with that either.
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/js/jquery-cookie.js"></script>
I had no luck with that either.
When you say "no luck" do you mean that the js file isn't loaded or do you mean that your other code still isn't working? Have you cleared your cache after putting that line in?
Thank you so much.
Your question was the answer.
The file wasn't being found.
Using this syntax...
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/js/jquery-cookie.js"></script>
...resulted in an src that had one too many "js" directories: /js/js/jquery-cookie.js.
I just changed the code to...
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/jquery-cookie.js"></script>
...and now it works fine. Thanks again for the pointer.
Your question was the answer.
The file wasn't being found.
Using this syntax...
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/js/jquery-cookie.js"></script>
...resulted in an src that had one too many "js" directories: /js/js/jquery-cookie.js.
I just changed the code to...
<script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/jquery-cookie.js"></script>
...and now it works fine. Thanks again for the pointer.