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:
There is an alternative solution available using:
xhrFields: {
withCredentials: true
}
Check here: How do I SET a Cookie (header) with XMLHttpRequest in JavaScript?.
Also, 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')
Note the '.' before the domain - that will set the cookie for example.com and all its subdomains.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…