json - Could not able to set and get cookies in jquery -
i trying set , cookies in jquery cant read them.
var objdata = {}; objdata.username = username; objdata.password = password; var urls = "gallries.aspx/checkuser"; alert(username + password); $.ajax({ type: "post", url: urls, data: "{'username':'" + username + "','password':'" + password + "'}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (response) { if (response.d == true) { alert(username); $.cookie("loggedinuser", username); alert($.cookie("loggedinuser")); alert('login success'); _loginmsg.addclass("success").removeclass("error"); _loginmsg.html("login successful!"); $('.user_login').animate({ 'top': '-165px' }, 800); $('#modal').fadeout(500); }
in if
block setting , trying in next step.
try :
success:{ setcookie(cname, cvalue, exdays); }
function set cookies (eg)
function setcookie(cname, cvalue, exdays) { var d = new date(); d.settime(d.gettime() + (exdays*24*60*60*1000)); var expires = "expires="+d.toutcstring(); document.cookie = cname + "=" + cvalue + "; " + expires; }
function cookies (eg)
function getcookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i]; while (c.charat(0)==' ') c = c.substring(1); if (c.indexof(name) == 0) return c.substring(name.length,c.length); } return ""; }
reffrence url : w3school
Comments
Post a Comment