Is it possible to call the server to set a new cookie with an AJAX request (that is, after the page is already loaded)?
For example, when a visitor accesses a link, ajax will open a php file that sets a new cookie as follows:
setcookie('cookiename', 'true', time()+3000, "/",'...');
But this is done after the html (the page containing the actual tag is <a>clicked) has been displayed. However, is it ok to set cookies in ajax? (possibly because the downloaded php file is separate from the original html page).
source
share