1

I am running into a problem with a cookie I want to access with both JavaScript and CF. I can create the cookie with JavaScript, like so:

document.cookie = 'SAVEDLISTINGS='+newc + ';path=/';

and on the next page CF can see it fine. However, if I use the same JavaScript to update the cookie with a new value, CF will not detect the change on subsequent pages. It retains its original value, as evidenced by the debug output and by dumping the Cookie scope.

JavaScript continues to see the correct cookie value, which I can check using Firefox developer tools. I assume this means the cookie file is being correctly updated. I do not see two cookies with the same name: only one, and it has the value as manipulated by the JavaScript.

I can delete the cookie in JavaScript, using

document.cookie = 'SAVEDLISTINGS=; expires=Thu, 01 Jan 1970 00:00:00 UTC' + ';path=/';

and this will delete the cookie from CF as well (on subsequent pages).

Note that I am not actually using CFCookie to manage the cookie, but I have experimented with setting it blank by ColdFusion (with httponly=no). This doesn't seem to make any difference.

Alexandre Neukirchen
  • 2,713
  • 7
  • 26
  • 36
JoeCopley
  • 51
  • 5
  • `I have experimented with setting it blank by ColdFusion (with httponly=no)` - so, usually ColdFusion has httponly=yes? – Jaromanda X Dec 23 '16 at 16:51
  • 2
    http://stackoverflow.com/questions/1336126/does-every-web-request-send-the-browser-cookies Could you check that the cookie is actually sent ? Maybe something invalidate it and is never sent back to the server. It should be in the request headers. – Loïc Faure-Lacroix Dec 23 '16 at 16:53
  • Using developer tools examine the outgoing request _after_ you set it with javascript and _send_ it to the subsequent page. Is the proper cookie code being set in the header? – Mark A Kruger Dec 23 '16 at 17:20

1 Answers1

1

Set the domain value of the cookie to make sure you are getting/setting the same exact cookie. You can view that info with Firebug. You can see below how two cookies named "testName" are treated as separate entities based on the domain. This is important so different sites can have the same cookie names without overwriting each other.

enter image description here

Jules
  • 1,941
  • 15
  • 18