Skip to main content
Inspiring
June 26, 2008
Answered

How to set a CFCOOKIE without a page reload?

  • June 26, 2008
  • 6 replies
  • 826 views
Is there a way to set a CFCOOKIE without a page reload when a user clicks a button/link/whatever? For example, an 'Add to cart' link.

Thanks!
This topic has been closed for replies.
Correct answer OldNapkin
Got it figured out. Here is an example in case anyone else would happen to need it.

6 replies

BKBK
Community Expert
Community Expert
June 28, 2008
A couple of points.

1) I don't think there should be a forward slash in the bind expression.
2) Your client code suggests the client determines the cookie value. Isn't that bad?
3) Though using 'value' as an attribute of <div> might work, 'value' is not an attribute of the tag.
4) Why all the HTML? Isn't something like the following sufficient?

BKBK
Community Expert
Community Expert
June 27, 2008
Dstharding, then your Javascript guess is good (document.cookie="username=BKBK; loggedIn=yes";)

Inspiring
June 27, 2008
BKBK, I'm pretty sure OldNapkin is saying he/she wants to use ajax remoting on the page or something so that the entire page doesnt reload, but cfcookie doesnt work until after the page reloads...
OldNapkinAuthor
Inspiring
June 27, 2008
quote:

Originally posted by: Dstharding
BKBK, I'm pretty sure OldNapkin is saying he/she wants to use ajax remoting on the page or something so that the entire page doesnt reload, but cfcookie doesnt work until after the page reloads...


That is exactly what I want to do. Can I use AJAX to call a Cookie-setting CFC with a click?

OldNapkinAuthorCorrect answer
Inspiring
June 27, 2008
Got it figured out. Here is an example in case anyone else would happen to need it.
BKBK
Community Expert
Community Expert
June 27, 2008
Just do <cfcookie> on the page the button/link/whatever is pointing to.

Inspiring
June 27, 2008
This is just a guess, but I bet you could set a cookie with Javascript and then access it later with cfcookie if you worked it right.

D
BKBK
Community Expert
Community Expert
June 27, 2008
I don't understand. Doesn't a page reload "when a user clicks a button/link/whatever? "