I am trying to set a cookie using jQuery:
$.cookie("testCookie", "hello"); alert($.cookie("testCookie"));
But when I load my page, I receive the error "$.cookie is not a function". Here is what I know:
I have looked at several other answers (here and here among others), to which most people suggested renaming the cookie.js file. I have renamed my cookie file "jquery.cookeee.js" but the results are the same.
Any ideas on what is going on here?
If it helps, I am creating a web application in MVC 4.
This question is tagged with
~ Asked on 2013-08-02 19:14:29
Here are all the possible problems/solutions I have come across:
$.cookie is not a standard jQuery function and the plugin needs to be downloaded here. Make sure to include the appropriate
<script> tag where necessary (see next).
When including the cookie script, make sure to include jQuery FIRST, then the cookie plugin.
This was my problem. Make sure you aren't including jQuery more than once. If you are, it is possible that:
In some rare cases, renaming the file to something that does NOT include ".cookie" has fixed this error, apparently due to web server issues. By default, the downloaded script is titled "jquery.cookie.js" but try renaming it to something like "jquery_cookie.js" as shown above. More details on this problem are here.
~ Answered on 2013-08-05 18:24:18
The old version of jQuery Cookie has been deprecated, so if you're getting the error:
$.cookie is not a function
you should upgrade to the new version.
The API for the new version is also different - rather than using
you should use
~ Answered on 2016-07-20 23:44:14