以动态形式jquery提交cookie

时间:2017-09-20 11:56:25

标签: javascript jquery html cookies

当用户点击href标记时,我正在创建一个动态表单并提交它。

这是代码

.contact .contact-form{
    width: 500px;
    margin: 0 auto;
    border: 1px solid #ccc;
    border-radius: 5px;    
}

问题是,我还必须提交一个cookie,该cookie先前在用户登录我的应用程序时设置。目前在后端,我没有得到cookie。

如何提交cookie。

1 个答案:

答案 0 :(得分:0)

You can then do:

$.cookie("test", 1);
To delete:

$.removeCookie("test");
Additionally, to set a timeout of a certain number of days (10 here) on the cookie:

$.cookie("test", 1, { expires : 10 });
If the expires option is omitted, then the cookie becomes a session cookie, and is deleted when the browser exits.

To cover all the options:

$.cookie("test", 1, {
   expires : 10,           //expires in 10 days

   path    : '/',          //The value of the path attribute of the cookie 
                           //(default: path of page that created the cookie).

   domain  : 'jquery.com',  //The value of the domain attribute of the cookie
                           //(default: domain of page that created the cookie).

   secure  : true          //If set to true the secure attribute of the cookie
                           //will be set and the cookie transmission will
                           //require a secure protocol (defaults to false).
});