开发者

Remove cookies from jquery ajax calls

开发者 https://www.devze.com 2023-03-17 16:47 出处:网络
I would do jquery ajax calls discardin开发者_如何学JAVAg every cookie, so I can have a new session for every call.

I would do jquery ajax calls discardin开发者_如何学JAVAg every cookie, so I can have a new session for every call.

Is there a way to do this?

Thanks


AJAX request is exactly an HTTP request (XMLHTTPRequest). Cookies get sent back and forth in the AJAX request-response headers in order to maintain the state of user session across multiple HTTP requests.

HTTP is an inherently stateless protocol and hence cookies are used to maintain the state of user's session across multiple HTTP requests.

Instead of removing cookies host all your static components(like images) in a Cookie-free Domain. The following url might might give you some info in this,

http://www.ravelrumba.com/blog/static-cookieless-domain/


As Harun pointed out, maybe you should consider a wider solution than deleting a session cookie that will alter the whole user session and not only your AJAX call.

To litteraly answer your question, you could delete the cookie you've set (provided you've set by yourself and not by another framework):

$.cookie("session", null);
$.ajax( url, [settings] )

But, that's probably not the good solution because you will delete the whole user session at each ajax call. You should tell us more about what you are doing so that we could help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消