Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cookie without page refresh

I am showing a jQuery overlay when users first visit a particular page

They have a radio button in the overlay that they can click to say they do not wish to see the notification again

I want to set a cookie that the user doesnt want to see the overlay again

Is it possible to set the cookie without refreshing the page?

I was going to make a ajax call back to the server and then set the cookie in the response headers but I guess they wont get set in an Ajax request/response?

Is it safe / OK to set the cookie purely from javascript? Or is that a bad idea?

any other options?

like image 357
ChrisCa Avatar asked Apr 15 '13 15:04

ChrisCa


1 Answers

There is no reason that an AJAX call cannot set a cookie. It is basically just an HTTP request.

AJAX Requests Get And Set Cookies Like Any Other HTTP Request

like image 200
Cloud SME Avatar answered Oct 03 '22 20:10

Cloud SME