⊗jsSpAXSC 259 of 294 menu

Passing cookies in AJAX requests in JavaScript

By default, cookies are not sent in AJAX requests. This means that a server session will not work. Usually, we still need to pass cookies. It can be enabled by credentials setting.

The 'include' value will cause cookies to be passed with the AJAX request (even if the request is cross-origin):

fetch('https://example.com', { credentials: 'include' });

The 'same-origin' value will also cause cookies to be passed, but only to the site where the script is running:

fetch('https://example.com', { credentials: 'same-origin' });

The 'omit' value disables the transmission of cookies:

fetch('https://example.com', { credentials: 'omit' });
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline