Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:11+00:00 2026-06-13T08:25:11+00:00

I have a webapp on www.example.com and an API on api.example.com. The webapp makes

  • 0

I have a webapp on http://www.example.com and an API on api.example.com.

The webapp makes ajax calls to the API.

Somewhere I need to put a cookie on api.example.com to keep sessions track.

To track my problem I’ve set test cookies on both subdomaines from the webapp and the api.
The webapp set a cookie on .exemple.com and the api set one on .exemple.com and another on api.exemple.com.
Cookies are set using Domain=.exemple.com only. No path, no HTTPOnly.

Note: In the end I need only one on api.exemple.com. But theses are for the tests.

Direct queries using my browser (Firefox 16) works fine.
Query on api: the two cookies are set and sent.
Query on www: the cookie is set and the two from the api is sent too. (Provided I query www after the api, of course).

Now, I clean the browser cookies and query www only.
Query on www: works fine, same as before.
Subquery on api, from www’s ajax request: no cookies are sent. Set-Cookies does nothing. Using Firebug I see the cookies in the response. But no traces of them on subsequent requests or the page informations.

I event tried to enable the cookies log on Firefox. Absolutly no traces of the cookies from api, not even a reject notice.

In the end I only need a way to store one cookie on api. And for that, I quite open 🙂

Informations:
The two servers are NodeJS.
I’ve tried to set the cookie on the server side (Set-Cookie header), on the client side (document.cookies), manually using firebug.

Others posts I’ve checked with no solutions (And many others which I don’t recall):

setting cross-subdomain cookie with javascript

Cookies and subdomains

Can subdomain.example.com set a cookie that can be read by example.com?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:25:12+00:00Added an answer on June 13, 2026 at 8:25 am

    Set the allow Credentials header on api

    Access-Control-Allow-Credentials: true
    

    Use withCredentials for the request

    $.ajax({
        url: a_cross_domain_url,
        xhrFields: { 
            withCredentials: true 
        }
    });
    

    Otherwise the XMLHttpRequest will not send the cookies, regardless of the Access-Control-Allow-Credentials header.

    Remove the wildcard on Access-Control-Allow-Origin

    Access-Control-Allow-Origin: http://www.example.com
    

    The wildcard * will not work. The browser will discard the response if withCredentials was set.

    References:

    http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/

    https://developer.mozilla.org/en-US/docs/HTTP_access_control

    http://arunranga.com/examples/access-control/credentialedRequest.html

    http://api.jquery.com/jQuery.ajax/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have /var/www/cool_codebase on www.example.com AND I have /var/www/cool_codebase on www.example.net The codebases are
i have an asp.net website http://www.site.com . This web app is also running on
I follow this example to localize img: http://www.wicket-library.com/wicket-examples/pub/?0 which works. There is just one
I have a url shortener in my web app, like http://myProject1.example.com/76sBdFAf6L This stuff should
I have two domain names www.example1.com www.example2.com When these come into tomcat I want
I have a webapp to be ran on Tomcat6/JbossAS 5 and, for versioning purposes,
I have a webapp that lists all of my artists, albums and songs when
I had the following idea: Say we have a webapp written using django which
OKay I lost alsmost the whole day on this. I have a webapp where
I have a maven3 webapp (war) project that has 2 dependencies. One is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.