以下是我遇到的所有可能的问题/解决方案:
1. Download the cookie plugin
$.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).
2.在cookie插件之前包含jQuery
当包含cookie脚本时,确保首先包含jQuery,然后是cookie插件.
<script src="~/Scripts/jquery-2.0.3.js" type="text/javascript"></script>
<script src="~/Scripts/jquery_cookie.js" type="text/javascript"></script>
3. Don't include jQuery more than once
This was my problem. Make sure you aren't including jQuery more than once. If you are, it is possible that:
- jQuery loads correctly.
- Cookie插件加载正确.
- 第二次包含jQuery将覆盖第一次,并销毁cookie插件.
For anyone using ASP.Net MVC projects, be careful with the default javascript bundle inclusions. My second inclusion of jQuery was within one of my global layout pages under the line @Scripts.Render("~/bundles/jquery")
.
4. Rename the plugin file to not include ".cookie"
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.