0

I am setting cookies using jquery+jquery cookie.

jQuery.cookie('status', 'active', {expires: 1, path: '/'});

Now how can I set this cookie using AJAX? regarless of jquery cookie, how would you set a cookie using ajax in jquery, anyone has any idea.

Links to original question (PHP & JQuery passing variables)

update

So I am making the AJAX request like so in my jquery code

$.ajax({
    url:  "script.php",
    type: "GET",
    data: { status: active}
    });

And in my php I am processing it like;

if($_GET['status']!='')
{
    setcookie("status", $_GET['status'], time()+3600);
}

but nothing is happening, no cookie is being set. can anyone see the problem,

1
  • what do you mean using AJAX? what do you need AJAX for? Commented Sep 13, 2013 at 3:09

1 Answer 1

1

You can set the cookies on the server the same you would for a normal page request. Just look into your server side language of choice's way of setting cookies. Ajax requests are nothing more than normal http requests. When the response gets back to the server the cookies will be set set by the browser.

PHP: http://www.w3schools.com/php/php_cookies.asp

Sign up to request clarification or add additional context in comments.

4 Comments

However, I need to set the cookie based on a jquery conditional
Ok, just pass a boolean in your Jquery ajax request that you can evaluate on the server. Either a query string param or a post parameter
ive never used ajax before, i dont know how to set the cookie with the help of ajax, im learning how to program

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.