Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

How to get cookie value with javascript or jquery

I am getting following cookie values on my home page.

vsettings=HiddenNotifications=%2C19%2C; (referral)|utmcmd=referral|utmcct=/; ASPSESSIONIDQCSBCCAD=LFLGDKACEGPCPFGBANHFFBMK; ASPSESSIONIDSASDCCDA=OFEHPJACGHNKICDLFBOCJNNH; ASPSESSIONIDQCSDDCBC=LGFPBDLCKHLIOLPMCAGJNFIM; ASPSESSIONIDQCTACBAC=DCIPJDLCNDBEGEIIELCGFMDP;CustomerID; ASPSESSIONIDSCTCAABD=LHPFFLFDEMIBIENBMGMLFIFP; ASPSESSIONIDSAQDDDAD=HMCDMLFDFCLJCIBHMEHPNHME; s_cc=true; __utmc=97358351; CustomerID=755B031ED8C016EC4F90D6F3127E776AE202DEF5BC6EB9F7A9BB19E49323BC3B; ASPSESSIONIDQCSDBDAC=CFBDJEAAPJJGHMDGOCCHALHC; ASPSESSIONIDSASCBDAD=FLGJHFAAJAJBICGIMOOJEFFF;Session%5FToken=C8F2A63C3BBA4E39BBF73B83C108D1C6

I want get the value of CustomerID cookie. Using jquery I wrote this:

$.cookie('CustomerID',{ path:'/'});

But I am not getting the value for cookie - it is showing me blank.

How can I get the CustomerId cookie?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you did is setting a cookie and not getting a cookie.

try var customerId = $.cookie('CustomerID');

or maybe you are trying to get the cookie from the root path but it's actually lives at a lower path..

Check out where you save the cookie!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...