Prevent Cookies From Being Sent on AJAX Request

前端 未结 5 1161
庸人自扰
庸人自扰 2021-02-05 00:58

I have a web service that I invoke from script but that does not need any information stored in cookies. Anytime I make a request to the service, the cookie is sent along with i

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 01:29

    Another approach would be prior to doing $.ajax:
    1. get the cookies from the browser for your domain with javascript (save them in a global variable)
    2. delete the cookies for your domain with javascript from the browser
    3. do the $.ajax call
    4. place the cookies (from the global variable) back in the browser.

    If you don't need the cookies from your domain at all just delete them (so skip 1. and 4.).

提交回复
热议问题