Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using AJAX to save cookies

Posted on 2011-02-27
1
Medium Priority
?
410 Views
Last Modified: 2012-05-11
How to use ajax to save content in the cookie so that i can use the user preferences in multiple pages?
0
Comment
Question by:dino_angelides
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34993309
To save we may use jQuery to simplify the code POST :
$.post("saveCookies.php", { "userid":$("#hiddenFieldUserId").val(),"cookies":encodeURIComponent(document.cookie) });

Open in new window


To restore, we may use GET, MAP and jQuery.Cookies
			$.get("getCookies.php", {"userid":$("#hiddenFieldUserId").val()}, function(cookies) {
				 $.map(cookies.split(";"), function(el, i) {
					  el = el.split("=");
					  cookieName = el[0].replace(/^\s+|\s+$/g,"");
					  cookieValue = unescape(el[1]);
					  $.cookie(cookieName, cookieValue);
				});
			});

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question