Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to set and get coockies in jquery but cant read.

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 was successful!");
                            $('.user_login').animate({ 'top': '-165px' }, 800);
                            $('#modal').fadeOut(500);                         
                        } 


in if block Iam setting and trying to get in next step..
Posted
Comments
F-ES Sitecore 30-Sep-15 4:27am    
Cookies you set won't be available to read until the next web request. If you want to store and read on the same page then put the data in a local variable, store the variable in the cookie but use the variable to read from rather than the cookie.

1 solution

Try to set cookie expire time here like:

JavaScript
$.cookie("loggedInUser", username, { expires : 10 }); //expires in 10 days


DEMO: FIDDLE[^]
 
Share this answer
 
Comments
Dawood507 30-Sep-15 4:45am    
I did like this but in console "Uncaught TypeError: $.cookie is not a function" error throwing where I mentione cookie plugin below jquery file.
Palash Mondal_ 30-Sep-15 5:00am    
Try to use this cookie js file:

https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js
Dawood507 30-Sep-15 5:49am    
I tried a lot ...again its not working..with your plugin too
Palash Mondal_ 30-Sep-15 5:53am    
Is the fiddle demo code working for you?
Dawood507 30-Sep-15 6:00am    
what its is? and where?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900