I've fixed the problem. Not sure if this works for all cases, but its
working for mine.
Here's what I did and what is incorrect/misleading in mootools docs.
Lets take three page examples: localhost:4000/ localhost:4000/
admin localhost:4000/admin/users
All was working well with no options to Cookie write() and dispose()
until I added the last page localhost:4000/admin/users at which
point, dispose() no longer worked.
Mootools docs (I'm using 1.2.3)
http://mootools.net/docs/core/Utilities/Cookie#Cookie-options
claims: In order to share the Cookie with pages located in a different
path, the Cookie.options.domain value must be set.
I'm not sure what this means anymore or if its simply wrong. At
first, I thought it meant I needed to set the domain for the deeper
path to find the same cookie as set in the shorter path. It
apparently does not mean this as my solution shows.
Here's what does work: setting the path, but not setting the domain!!!
As follows:
Cookie.write('my_cookie', 'my_data', {path: '/'});
Cookie.dispose('my_cookie', {path: '/'});
I hope this exploration helps others. fyi, for whoever manages the
mootools doc pages, one of the best community docs I've every used was
the mysql docs, which enable any user to add footnotes, wiki-style, to
the bottom of doc pages. In many cases, the user contributed notes
were more valuable than the official docs.
thanks, Jon
On Nov 8, 10:09 pm, Jon Hancock <[email protected]> wrote:
> Thanks, I've tried:
> Cookie.write('session', json["cookie"], {domain: 'localhost:4000'});
> and no cookie gets written.
> Any more ideas?
> Jon
>
> On Nov 8, 9:12 pm, "Steve Onnis" <[email protected]> wrote:
>
>
>
> > The domain isnt LocalHost in that instance, it is LocalHost:4000
>
> > If you specify a port on a host name, the port is also part of the domain,
> > just like LocalHost and LocalHost:80 are different
>
> > -----Original Message-----
> > From: Jon Hancock [mailto:[email protected]]
> > Sent: Monday, 9 November 2009 12:59 PM
> > To: MooTools Users
> > Subject: [Moo] Cookie.write and dispose acting flaky
>
> > My user object has the following methods:
>
> > login: function(message){
> > new MyDialog({
> > caption: 'Please Login',
> > url: '/login',
> > width: '450px',
> > message: message,
> > jsonSuccess: function(json){
> > dbug.log("LOGIN SUCCESS")
> > Cookie.write('session', json["cookie"]);
> > user.fireEvent('loggedIn');
> > }
> > });
> > },
> > logout: function(){
> > dbug.log("LOGOUT");
> > Cookie.dispose('session');
> > this.fireEvent('loggedOut');
> > window.location = '/';
> > }
>
> > All was working well until I started adding pages with deeper paths.
> > The above code works in these two pages: localhost:4000/ and
> > localhost:4000/admin But with page localhost:4000/admin/users the
> > call to dispose the cookie does not work. The logout function does
> > everything correct expect actually dispose the cookie.
>
> > According to docs ( I am using mootools
> > 1.2.3)http://mootools.net/docs/core/Utilities/Cookie#Cookie:write => In
> > order to share the Cookie with pages located in a different path, the
> > Cookie.options.domain value must be set.
>
> > When I try setting options for domain and path, the call to Cookie
> > write does not work:
> > Cookie.write('session', json["cookie"], {domain: 'localhost', path:
> > '/'});
>
> > This is seriously not the path of least surprise. I've tried several
> > combinations for options and can't get it to work. All I want is a
> > single cookie called "session" to be written or disposed anywhere in
> > my app.
>
> > Any advice? thanks, Jon