tags:

views:

52

answers:

3

Hi, i with jquery delete cookies

$.cookie('name', '', { expires: -1 });

refresh page and still cookies is in browser (memory),

alert('name:' +$.cookie('name'));

show name: Gloris. Why? Thanks

+1  A: 

You are deleting a cookie titled 'name' and alerting a cookie titled 'the_cookie'.

Reinis I.
soory, when i copy - mixed codes.
A: 

To delete a cookie with JQuery, set the value to null:

$.cookie("name", null);

Edit: The final solution was to explicitly specify the path property whenever accessing the cookie, because the OP accesses the cookie from multiple pages in different directories, and thus the default paths were different (this was not described in the original question). The solution was discovered in discussion below, which explains why this answer was accepted - despite not being correct.

Chadwick
But from the source here: http://plugins.jquery.com/files/jquery.cookie.js.txt : `if (value === null) { value = '';options.expires = -1;}`, that what goes inside the processing function, so they are supposed to perform the same. (parameters are `(name, value, options)`)
aularon
Chadwick>thanks for help, but it did not work
Is the cookie setting code and test code on the same page? If not, you'll need to explicitly set the `path` in the options to both commands, as it defaults to the path of the current page. Test by setting to root of your domain both in all places where the cookie is read and written: `$.cookie('name', value, {path:'/'})`
Chadwick
Chadwick>Maybe you are right. For exm. i set cookies in site.com, then go in site.com/user, site.com/user/mod, site.com/user/mod/new and i wish see cookies in all this page. How must looks like path, like this: {path:'/'}?
@gloris Correct, so in every use of the cookie (read or write) specify the same path, since as you describe, the default path is different for many of your pages. If that works, I'll note in this answer that the final solution is in these comments.
Chadwick
A: 

As in the documentation here, what you ar edoing is how to do what you wanna achieve, the problem must be some other place, probably the cookie is being set again somehow on refresh.

aularon