Setting a cookie using Atlassian Javascript

Rashedul Hasan July 1, 2012

Hi

I'm trying to set a cookie using Atlassian Javascript (AJS) by an Ajax call like the following:

AJS.Cookie.save("DREAMBROKER_COOKIE", "https://sendview.to/com.php?action=validate3&accessname=userName&password=password ");
alert("success in setting cookie"+ AJS.Cookie.read("DREAMBROKER_COOKIE"));

This way setting the cookie isn't working. If I set the cookie value directly using browser, it works. So, my cookie setting is not perfect. Can anyone help me set the cookie using AJS or provide any Atlassian workaround on this?

Thanks

Rashed

1 answer

1 vote
Dennis Kromhout van der Meer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2012

For me it does work if I put it on DocReady. For example:

AJS.$(document).ready(function() {
	AJS.Cookie.save("test","banana");
	var mycookie = AJS.Cookie.read("test");
	alert(mycookie);
});

Rashedul Hasan July 4, 2012

Hi

Thanks...so according to you the format I posted above should work, right? Unfortunately it's not working. When I hit the above mentioned url:

https://sendview.to/com.php?action=validate3&accessname=userName&password=password

through browser, I get my cookie and can work which are dependent on that. Could you tell me how I can achieve that?

Thanks

Dennis Kromhout van der Meer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

Oh wait, you're not trying to cookie save the url, but the result when calling this url?

Rashedul Hasan July 4, 2012

Right, I want to save the result when calling the url. Is it possible to save the result as cookies?

Also, if that's not possible, I want to save cookies like the following one using accessname and another using password (better way I think):

AJS.$.cookie("accessname", encodeURIComponent(<userName>), {expires: 1, path: '/', domain: 'sendview.to', secure: true} );

In this format if I remove domain (sendview.to) and secure params, it works well but with these it doesn't work. Notice that I used JQuery cookie not the atlassian one because in atlassian format like below:

AJS.Cookie.save("test","banana");

I can give the cookie name and value only but I need to provide other params like path, expire, domain etc. Is there a way to provide all these params in AJS.Cookie.save("test","banana") this format?

Thanks

Suggest an answer

Log in or Sign up to answer