Home >Web Front-end >JS Tutorial >Problems encountered when using Jquery.cookie.js
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!