Home > Web Front-end > JS Tutorial > body text

Problems encountered when using Jquery.cookie.js

一个新手
Release: 2017-09-29 09:54:09
Original
1404 people have browsed it

jquery.cookie.jsBasic operations

$.cookie("key","value"); //写入
$.cookie("key","update value");//修改
$.cookie("key",null);//删除
Copy after login

If $.cookie("key","value") writes the cookie, but does not set the path, the default path will be used when creating the cookie for you. The path of the current operation page

For example:

Write a $.cookie("user","zhangsan"); on the http://localhost:8001/user/list page; pass When viewing the developer tool, the path is /user/list

Write a $.cookie("user","zhangsan1") on the http://localhost:8001/pay/list page; through the developer tool When viewing, the path is /pay/list

. In this way, when you get $.cookie("user") on other pages; you will always get the value zhangsan written for the first time, and the modification will not be successful. , the same is true for deletion

So it is best to specify the path when writing cookies, such as: $.cookie("key","value",{path:"/"});

In this way, no matter which page you are on, you can modify, update, or delete the cookie value of the corresponding key

The above is the detailed content of Problems encountered when using Jquery.cookie.js. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!