Home  >  Article  >  Web Front-end  >  Problems encountered when using Jquery.cookie.js

Problems encountered when using Jquery.cookie.js

一个新手
一个新手Original
2017-09-29 09:54:091413browse

jquery.cookie.jsBasic operations

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

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!

Statement:
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