prevent曲奇被发送的Ajax请求 [英] Prevent Cookies From Being Sent on AJAX Request

查看:131
本文介绍了prevent曲奇被发送的Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的脚本中调用但是,这并不需要存储在cookie中的任何信息的Web服务。每当我提出一个请求到服务,该cookie与它一起发送。据我所知,在默认情况下cookie发送与HTTP请求,但有什么办法都重写该行为,而不是发送cookie?

在简单地说,我发我的要求是这样的:

  $。阿贾克斯({
    键入:POST,
    缓存:假的,
    网址:网址,
    数据:数据,
    的contentType:应用/ JSON的;字符集= UTF-8,
    数据类型:JSON,
    成功:函数(响应){successFunc(响应); },
    错误:函数(XHR){errorFunc(XHR); }
});
 

解决方案

发送AJAX请求到cookie的服务器上的子域。所以,你的应用程序是www.mydomain.com和Ajax请求从api.mydomain.com你从未设置上的cookie服务。另外一个伟大的想法,与像图像静态文件做到这一点等等...

请参阅使用Cookie的免费域名的组件的<一节href="http://developer.yahoo.com/performance/rules.html">http://developer.yahoo.com/performance/rules.html

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 it. I understand that by default cookies are sent with HTTP request, but is there any way at all to override that behavior and not send the cookie?

In a nutshell, I am issuing my request like this:

$.ajax({
    type: "POST",
    cache: false,
    url: url,
    data: data,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) { successFunc(response); },
    error: function(xhr) { errorFunc(xhr); }
});

解决方案

Send AJAX requests to cookie-less subdomain on your server. So you app is www.mydomain.com and ajax requests are served from api.mydomain.com which you never set a cookie on. Also a great idea to do this with static files like images etc...

see the "Use Cookie-free Domains for Components" section of http://developer.yahoo.com/performance/rules.html

这篇关于prevent曲奇被发送的Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆