Jquery delete cookie invalidation solution

  • 2020-03-29 23:42:24
  • OfStack

Recently I did a function, but it always failed to delete the cookie, I don't know why.

Using the $. Cookies (" name ", "");   The result is a cookie with a new null value.

Using the $. Cookies (" name ", null); You can't delete the cookie.

Finally using $. Cookies (" name ", null, {path: "/"});   It worked at last.      

Maybe it is a bug of $. Cookie. I wonder if the latest version has fixed this bug.

Here are some other $. Cookie by the way reproduced to spare:


$(function(){
var COOKIE_NAME = 'test_cookie';
//Set the cookie through the interval
$('a').eq(0).click(function() {
$.cookie(COOKIE_NAME, 'test', { path: '/', expires: 1 });
return false;
});
//Set the cookie to expire
$('a').eq(1).click(function() {
var date = new Date();
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
$.cookie(COOKIE_NAME, 'test', { path: '/', expires: date });
return false;
});
//To get a cookie
$('a').eq(2).click(function() {
alert($.cookie(COOKIE_NAME));
return false;
});
//Delete the cookie
$('a').eq(3).click(function() {
$.cookie(COOKIE_NAME, null, { path: '/' });
return false;
});
}); 


Related articles: