jQuery的ajax调用不发送的cookie [英] jquery ajax call not sending cookie

查看:471
本文介绍了jQuery的ajax调用不发送的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对面的正常工作,除了它没有发送cookie的一个子jQuery的AJAX调用。有没有办法做到这一点?

I have a jQuery ajax call across a subdomain that works correctly except it's not sending the cookie. Is there any way to accomplish this?

推荐答案

这听起来像我预期的行为。 Cookies是每个域(这包括子域)。但是,我认为你可以像这样迫使它:

This sounds like expected behavior to me. Cookies are per domain (and that includes subdomains). But I think you can force it with something like this:

$.ajax({
   headers: {'Cookie' : document.cookie },
   url: "sub.domain.com",
   success: function(){ ...

这是没有经过测试的,所以让我知道,如果它的工作原理;)

This is totally untested so let me know if it works ;)

编辑其实现在看来似乎是不可能的:

EDIT actually it seems like it's not possible:

其实,它看起来像它不可能在所有...看看这里:<一href="http://stackoverflow.com/questions/2320110/how-do-i-set-a-cookie-header-with-xmlhtt$p$pquest-in-javascript">How做我设置cookie(头)与XMLHtt prequest在JavaScript?你可能会对SOL

Actually it looks like its not possible at all... look here: How do I SET a Cookie (header) with XMLHttpRequest in JavaScript? you might be SOL

但它认为你可以设置的cookie在PHP,使它们在您的所有子域名有效。事情是这样的:

But it think you can set the cookies in php so that they are valid across all your subdomains. Something like this:

ini_set('session.cookie_domain', '.example.com')

请注意了。域之前 - 这将设置为example.com及其所有子饼干

Note the '.' before the domain - that will set the cookie for example.com and all its subdomains.

您可以使用上述在你的应用程序中设置session.cookie_domain或将其设置在php.ini。

You can set session.cookie_domain in your app using the above or set it in your php.ini.

以上是从这里 被盗

The above is stolen from here

这篇关于jQuery的ajax调用不发送的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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