Home > Web Front-end > JS Tutorial > jquery solution to invalid cookie deletion_jquery

jquery solution to invalid cookie deletion_jquery

WBOY
Release: 2016-05-16 17:16:04
Original
1347 people have browsed it

I recently made a function, but it always failed when deleting cookies. I can’t figure out why.

Using $.cookie("name",""); The result is that a new cookie with an empty value is generated.

Use $.cookie("name",null); and the cookie cannot be deleted.

Finally use $.cookie("name",null,{path:"/"}); and finally succeeded.

Maybe it’s a bug in $.cookie. I wonder if the latest version has fixed this bug.

The following are some other $.cookies that are reprinted for later use:


Copy code The code is as follows:
$(function(){
var COOKIE_NAME = 'test_cookie';
//Set cookie through time interval
$('a').eq(0).click(function () {
$.cookie(COOKIE_NAME, 'test', { path: '/', expires: 1 });
return false;
});
// Set cookie, to Period time
$('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;
});
// Get cookie
$('a').eq(2).click(function() {
alert($.cookie(COOKIE_NAME));
return false;
});
//Delete cookie
$('a').eq(3).click(function() {
$.cookie(COOKIE_NAME, null, { path: '/' });
return false;
});
});

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template