0

I own 2 domains, A and B, hosted with web applications. From an application in domain A, I call a service in B, which takes some time. So I show a loading GIF.

In the service in B, I set a cookie along with the response in Java:

HttpResponse resp;        
Cookie fileDownloadStatus = new Cookie("fileDownload", "true");
fileDownloadStatus.setPath ("/App");
fileDownloadStatus.setDomain("x.x.x.x");
resp.addCookie(fileDownloadStatus);

In A, I keep looking for the cookie, so I can stop the loading GIF, but I am unable to get the cookie in JavaScript, even though I tried setting the path of the cookie and the domain for the cookie as if it were sent from A:

var fileDownloadCheckTimer;
fileDownloadCheckTimer = window.setInterval(function () {
    var cookies = document.cookie;
    console.log(cookies);
    var cookieArray = cookies.split(';');
    console.log(cookieArray);
    for(var i=0;i<cookieArray.length;i++)
    {
        var reqCookie = cookieArray[i].split('=');
        console.log(reqCookie);
        if(reqCookie[0]=="fileDownload")
        {
            if(reqCookie[1] == "true")
                finishDownload();
        }
    }
}, 1000);

Please assist.

Boann
  • 44,932
  • 13
  • 106
  • 138
Prashanth
  • 31
  • 7
  • 1
    You can't do this. You can't set or access cookies across different second-level domains. – Boann Nov 13 '14 at 16:04
  • 1
    are both domain sharing a same private suffix ? like aa.mydomain.com and bb.mydomain.com ? then cookie on mydomain.com can be read/write by both. see http://stackoverflow.com/questions/5258126/domain-set-cookie-for-subdomain – philippe lhardy Nov 13 '14 at 17:11
  • No @philippelhardy they are not the same domain or sub-domain, they are completely different domains. But still I Own both of them and both of them are Intranet Domains. Can't we set a cookie for a application in Domain A from an application in Domain B? – Prashanth Nov 14 '14 at 10:38

0 Answers0