Per my study, Anup ’s reply should be able to help on your issue.
Since we haven’t heard from you for some days, I am marking Anup’s reply as answer now. If Anup's reply did not resolve your problem, please feel free to unmark the answer. If you have further issue but different than the original one in this thread, please
open a new question. Thanks for your cooperation.
Thanks,
Yanping Wang
Please mark the replies as answers if they help or unmark if not.
Feedback to us
dotnet_CH
Member
40 Points
277 Posts
array of cookie in jquery
Dec 09, 2012 10:35 AM|LINK
hi all,
i want get and set method for 2 dimential cookie
cookie = {username, true(superuser)}
cookie = {username, true(referral)}
how to save and get cookie in pair
i want to status of superuser with username
entity is username along with true/false.
i will save these values after signin and validation process
and save these settings along with user name and next time same user comes, i will going to set these propties before signin
please review this work flow and improve it if required and please let me know the code to use cookies in pair which is most important for me.
thanks
bruce (sqlwo...
All-Star
37594 Points
5573 Posts
Re: array of cookie in jquery
Dec 09, 2012 06:46 PM|LINK
this is a really insecure approach as anyone can modify their cookies before being sent.
asteranup
All-Star
30184 Points
4906 Posts
Re: array of cookie in jquery
Dec 10, 2012 03:54 AM|LINK
Hi,
You can create an array of objects and use JSON.stringfy and $.parseJSON for this purpose. Check the following code-
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js" type="text/javascript"></script> <script> function setCookie(c_name, value, exdays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()); document.cookie = c_name + "=" + c_value; } function getCookie(c_name) { var i, x, y, ARRcookies = document.cookie.split(";"); for (i = 0; i < ARRcookies.length; i++) { x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=")); y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == c_name) { return unescape(y); } } } $(document).ready(function () { var users = [ { username: "user 1", status: true }, { username: "user 3", status: true }, { username: "user 3", status: false }, { username: "user 4", status: false } ]; //setCookie setCookie("userdetails", JSON.stringify(users), new Date()); debugger; //getCookie var userFromCookie = $.parseJSON(getCookie("userdetails")); }) </script> </head> <body> <form id="form1" runat="server"> </form> </body> </html>Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Yanping Wang...
All-Star
15181 Points
1552 Posts
Microsoft
Re: array of cookie in jquery
Dec 21, 2012 06:48 AM|LINK
Hi dotnet_CH,
Per my study, Anup ’s reply should be able to help on your issue.
Since we haven’t heard from you for some days, I am marking Anup’s reply as answer now. If Anup's reply did not resolve your problem, please feel free to unmark the answer. If you have further issue but different than the original one in this thread, please open a new question. Thanks for your cooperation.
Thanks,
Yanping Wang
Feedback to us
Develop and promote your apps in Windows Store