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 9134987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:45:52+00:00 2026-06-17T08:45:52+00:00

I can’t seem to get cookies set on my browser in javascript to be

  • 0

I can’t seem to get cookies set on my browser in javascript to be sent as part of a jQuery ajax request to a sub-domain web application.

I have two web applications, one on a root domain and one on a sub-domain. To get around cross site scripting restrictions, my sub-domain web application implements a global action filter to add the Access-Control-Allow-Origin header to the root domain of all its http responses. This allows ajax calls from the root domain to the sub-domain to work.

But, when I create a cookie in javascript using the following code…

var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = 'searchId=' + ids.generateGUID() + ';domain=' + ".root.example.com" + ';path=/;expires=' + myDate;

… the cookie is not passed in the subsequent ajax requests to the-sub domain server.

I thought that the CORS header and setting the domain and path in the cookie would allow the sub domain web application access to the cookie but the browsers (chrome 21.0.1180.89 & firefox 17.0.1) don’t seem to supply the cookie.

Am I misunderstanding browser cookie access restrictions when using sub-domains and ajax requests?

Thanks

  • 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-17T08:45:53+00:00Added an answer on June 17, 2026 at 8:45 am

    In order for cookies to work with CORS, you need to do two things.

    First, your server needs to respond with the following header:

    Access-Control-Allow-Credentials: true
    

    Second, your XmlHttpRequest object needs to set the withCredentials property:

    xhr.withCredentials = true;
    

    This should send the remote domain cookies in the request, although the cookie must be set by the remote server.

    Your JS code itself still will not have access to the cookies, nor can it set cookies on a remote domain. There is no way, AFIAK for JS code to access another domain’s cookies.

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

Sidebar

Related Questions

Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
I have a jquery bug and I've been looking for hours now, I can't
Can MOSS integrate and get user profiles from multiple Active Directory and/or LDAP stores?
Can anyone tell me what i am doing wrong? I am trying to get
Can anyone direct me to a good tutorial on how to set up virtual
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Can anyone can confirm the best idea for storing jquery code, initially i was
Can we change the HTML or its attributes of the selected part of the
Can find why i get this error can someone help? package Android.data; public class

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.