How to set the jQuery cookie for a URL with Fragment?

advertisements

I am using the jquery cookie plug-in https://github.com/carhartl/jquery-cookie.

I saw this reference on how to build a URL with Fragment: AJAX Applications Crawlable

The final url rule looks like this:

localhost/site/search#!key__searchword&page=1
localhost/site/search#!key__searchword&page=2
localhost/site/search#!key__searchword&page=3

(original url should like this: localhost/site/search?_escaped_fragment_key=searchword&page=1)

Each above page has one button, I want to check:

  • If user never clicked, he/she can do the click,
  • If user has clicked, then add class voted for forbidden click again.
  • I want set cookie for 7 days.

My javascript code:

$(document).ready(function(){
  $(".up").live('click',function() {
    $.cookie('up', 'vote', { expires: 7, path: '/', domain: 'http://127.0.0.1/site/' });
    var up = $.cookie('up');
    if (up == 'vote') {
        $(".up").addClass('voted');
    };
  });
});

In anycase, the jquery cookie does not work for me. How can I set the jquery cookie for a URL with Fragment?


Fragments are never sent to the server, so you cannot set a cookie for a fragment. You can only set a cookie for the path, and it defaults to the path up to the last forward slash I believe according to the RFC.