开发者

jQuery cookie gets immediately unset - but only the first time it's set

Why might the below only work after the first time? A null cookie is all there is after clicking on a menu item, but every time after that it works perfectly...

I'm using the jquery cookies plugin.

$j(document).ready(function(){

$j('#menu-main-nav-menu li').each(function(index) {
    $j(this).data('sc-menu-item', index);
    })

currentPage = $j.cookie('currentPage');
        // do some stuff with the cookie value here

$j('#menu-main-na开发者_如何学Cv-menu li').click(function() {
    $j.cookie('currentPage', $j(this).data('sc-menu-item'))
});

});

Thanks very very much for any help - i'm stuck!


nashe ,

I don't think there is anything wrong with the cookie plugin , do the following ways to debug

print the value before it sets

use console.log($j(this).data('sc-menu-item')); or alert//

that value might be null..

the abovedebuging should fix the problem


put an event.preventDefault() into the link click event, then setting the cookie, and then forward onwards with the link and see if that makes a difference.


It turns out the js was fine. I set the cookie in the wrong domain... novice that i am...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜