Cookie Always Null?
I want to check if the cookie is existing or not The problem is it is always returning to null if i check it if ($.cookie('cookieCreditDash') == null) { //CODE ALWAYS ENTER HER
Solution 1:
What is $.cookie
? a jquery plugin?
Did you try using document.cookie
for setting cookie instead of $.cookie
.
https://developer.mozilla.org/en-US/docs/DOM/document.cookie
Solution 2:
As I can see from documentation jquery.cookie.js: expires
is number of days
if ($.cookie('cookieCreditDash') == null)
{
$('div').text("no cookie");
$.cookie("cookieCreditDash", 'test', {expires: 1});
} else{
var data = $.cookie("cookieCreditDash");
$('div').text("with cookie: " + data);
}
Solution 3:
Looks like you are using jQuery cookie plugin.
Besides cookie expiry issues, you might also want to check your cookie path, making it available to all paths on your domain. You can do so by writing following code,
$.cookie("cookieCreditDash", "Value", { path: '/' });
Without {path: '/'}
, cookie path will be limited to current path level only.
Post a Comment for "Cookie Always Null?"