Can headers be sent on AJAX request?

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).

+3
source share
3 answers

, cookie. , cookie - HTTP, HTML-; , HTML , . ajax HTTP- , (,!) HTTP- ; Set-Cookie.

PHP, , PHP, cookie ( , ). , . JSP, ASP.

+3

cookie AJAX , . ( .) , cookie XmlHttpRequest, , IE, Chrome Firefox.

+1

Why not use javascript to edit cookies? Return the contents of the cookie in JSON format and use javascript to store the values.

0
source

Source: https://habr.com/ru/post/1733350/


All Articles