When I try to load my page that uses jquery, when the following line is hit:
if ($.cookie('compare') != null)
I get the error $.cookie is not a function. Has anybody seen this before?
Cookies are data, stored in small text files, on your computer. When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user.
This function uses JavaScript's string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by "=" producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read.
To update a cookie, simply overwrite its value in the cookie object. You do this by setting a new cookie on the document with the same Name, but a different Value.
You can use setCookie('name', 'value', 0) to delete a cookie.
That means that the $.cookie
plugin isn't being included in the page, at least not being it's getting called. Make sure it's both being included, and is being included before it's getting used. Include it just after jQuery itself to be safe.
Just a tip: Several other plugins rely on the cookie plugin (but don't necessarily check if it exists before calling it), you could be using one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With