jQuery的$ .cookie不是一个函数 [英] jQuery $.cookie is not a function

查看:1513
本文介绍了jQuery的$ .cookie不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置使用jQuery的cookie:

I am trying to set a cookie using jQuery:

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

但是,当我载入我的网页,我收到错误$ .cookie不是一个函数。以下是我知道的:

But when I load my page, I receive the error "$.cookie is not a function". Here is what I know:

  • I have downloaded the jQuery cookie plugin here.
  • I am linking to jQuery and THEN the cookie plugin.
  • Both jQuery and jQuery.cookie are loading correctly with 200 OKs.

我已经看过其他几个答案(这里 和的here ),大多数人认为它重命名cookie.js文件。我已经改名为我的Cookie文件​​jquery.cookeee.js,但结果是一样的。

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?

如果有帮助,我创造了MVC 4 Web应用程序。

If it helps, I am creating a web application in MVC 4.

推荐答案

如果于 $。cookie的其他人绊倒不是一个函数的问题,这里有所有可能的问题/解决方案,我所遇到的:

If anyone else stumbles upon the $.cookie is not a function problem, here are all the possible problems/solutions I have come across:


  • 该Cookie插件没有下载。 $。饼干不是一个标准的jQuery功能和插件需要在这里下载 。确保包括相应的​​<脚本方式> 标记在必要时(见下)

  • 当包括cookie的脚本,确保包括jQuery的,再cookie的插件。

  • The cookie plugin was not downloaded. $.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.

即。你的头可能包含:

<script src="~/Scripts/jquery-2.0.3.js" type="text/javascript"></script>

然后

<script src="~/Scripts/jquery_cookie.js" type="text/javascript"></script>


  • 在某些情况下,重命名文件的东西,不包括.cookie已经修复了这个错误,显然是由于网络服务器的问题。默认情况下,下载的剧本名为jquery.cookie.js,但尝试重命名为类似如上图所示jquery_cookie.js。对这个问题的更多细节 href=\"https://drupal.org/node/728412\">。

  • 最后(这是我的问题),请确保您不包括jQuery的不止一次。如果是,则可能是1 jQuery的正确加载2. cookie的插件加载正确3.最后你的jQuery第二纳入覆盖第一和毁坏cookie插件。

    • In some 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.
    • Lastly (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. Finally your second inclusion of jQuery overwrites the first and destroys the cookie plugin.
    • 有关使用ASP.Net MVC项目的人,要小心使用默认的JavaScript捆绑包裹;它们可以是有时很难找到。我的jQuery第二是包容的行 @ Scripts.Render在我的全球布局页之一中(〜/包/ jQuery的)。我个人preFER不渲染包​​,只是链接到JavaScript作为必要的。

      For anyone using ASP.Net MVC projects, be careful with the default javascript bundle inclusions; they can be hard to find sometimes. My second inclusion of jQuery was within one of my global layout pages under the line @Scripts.Render("~/bundles/jquery"). I personally prefer not rendering bundles and just linking to javascript as needed.

      欢呼和特别感谢凯文乙就这一个帮助。

      Cheers and special thanks to Kevin B for the help on this one.

      这篇关于jQuery的$ .cookie不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆