jQuery $.cookie is not a function

前端 未结 7 1596
眼角桃花
眼角桃花 2020-11-27 15:12

I am trying to set a cookie using jQuery:

$.cookie(\"testCookie\", \"hello\");
alert($.cookie(\"testCookie\"));

But when I load my page, I

7条回答
  •  广开言路
    2020-11-27 15:41

    Here are all the possible problems/solutions I have come across:

    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

    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:

    1. jQuery loads correctly.
    2. The cookie plugin loads correctly.
    3. Your second inclusion of jQuery overwrites the first and destroys the cookie plugin.

    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.

提交回复
热议问题