syrkull
syrkull

Reputation: 2344

store user prefrences in jQuery

I have the following code for my ad system:

 function showandhide()
 {
    if ($('.showandhide').html() == 'show ads')
    {
       $('.showandhide').html("show ads");
       $('.ads').hide();
    }
    else 
    {
       $('.showandhide').html("hide ads");
       $('.ads').show();
    }
 }

The code is very simple. It hides and shows ads in my website. The problem is that it does not store the user preferences. How do I store them? Is there a fast way without using a database? I do not feel like creating a code to store information to my database just for hiding and showing ads. Is there any other fast solutions? maybe something in jQuery?

Upvotes: 0

Views: 75

Answers (2)

Philemon philip Kunjumon
Philemon philip Kunjumon

Reputation: 1422

If you are trying to store the detail temporarily you can save it in a session. for that you can use jquery ajax..

$.ajax({
   url: '/update-session.php',
   data:"detail="+detail,
   type: 'post',
   success:function(data){
       // if you care. 
   }
});

server side

$_SESSION['pageX'] = $_POST['detail'];

ADDITION

in order to check if the session variable exists or not

check this link php Session_id_registered

and you want to save the session only when you click a button. you can give that by using jquery click event..

hope this helps!!

Upvotes: 2

PleaseStand
PleaseStand

Reputation: 32082

jStorage allows you to store JavaScript objects in the user's web browser. It works in both recent browsers and in old versions of IE.

If you need to access the preference data from server-side code, consider setting a cookie instead using the jQuery Cookie plugin. The drawback is that setting a cookie slightly increases bandwidth usage, as the browser has to send it for each HTTP request.

Both of these allow you to avoid storing the data in a database on your server.

Upvotes: 1

Related Questions