最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery cookie issue: $.cookie is not a function - Stack Overflow

programmeradmin3浏览0评论

I know this question has been asked multiple times. I looked at many answers but couldn't find a solution.

I am trying to load jquery.cookie.js script. Here is how:

<script src=".1.4/jquery.min.js"></script>
<script src=".11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript" src="scripts/javascript.js"></script>

This is my javascript:

$(document).ready(function () {
    var jobStats_class = $.cookie('jobStats');

    // Add toggle feature
    $('.jobStats caption').click(function () {
        $('.jobStats th,.jobStats td').slideToggle('1000');
    });

    $('.ricSubscriptions caption').click(function () {
        $('.ricSubscriptions th,.ricSubscriptions td').slideToggle('1000');

    });

    $('.trthJobStatus caption').click(function () {
        $('.trthJobStatus th,.trthJobStatus td').slideToggle('1000');
    });
});

Thanks for your help!

I know this question has been asked multiple times. I looked at many answers but couldn't find a solution.

I am trying to load jquery.cookie.js script. Here is how:

<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis./ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript" src="scripts/javascript.js"></script>

This is my javascript:

$(document).ready(function () {
    var jobStats_class = $.cookie('jobStats');

    // Add toggle feature
    $('.jobStats caption').click(function () {
        $('.jobStats th,.jobStats td').slideToggle('1000');
    });

    $('.ricSubscriptions caption').click(function () {
        $('.ricSubscriptions th,.ricSubscriptions td').slideToggle('1000');

    });

    $('.trthJobStatus caption').click(function () {
        $('.trthJobStatus th,.trthJobStatus td').slideToggle('1000');
    });
});

Thanks for your help!

Share Improve this question edited Jun 4, 2015 at 14:40 Tushar 87.3k21 gold badges163 silver badges181 bronze badges asked Jun 4, 2015 at 14:35 Himanshu GuptaHimanshu Gupta 7172 gold badges9 silver badges16 bronze badges 9
  • Can you tell us if the jquery.cookie.js request succeeds? – tvanfosson Commented Jun 4, 2015 at 14:37
  • @tvanfosson - it does! no error reported regarding loading of the actual file. – Himanshu Gupta Commented Jun 4, 2015 at 14:38
  • URL for the site with the problem? – tvanfosson Commented Jun 4, 2015 at 14:41
  • Which version of jquery.cookie are you using ? – jmgross Commented Jun 4, 2015 at 14:41
  • @huggilou - I am using 2.0.0 from github. I just followed Alex's suggestion and it solved the problem! – Himanshu Gupta Commented Jun 4, 2015 at 14:45
 |  Show 4 more ments

2 Answers 2

Reset to default 5

Since version 2.0, jquery-cookie project has moved to js-cookie project.

Now you can't handle cookies with $ variable (because this library didn't really use special functions of jQuery). Now, you have to use Cookies variable :

Create a cookie

//OLD
$.cookie('name', 'value', { expires: 7, path: '/' });
//NEW
Cookies.set('name', 'value', { expires: 7, path: '/' });

Read a cookie

//OLD
$.cookie('name');
//NEW
Cookies.get('name');

Read all cokies

//OLD
$.cookie();
//NEW
Cookies.get();

Delete a cookie

//OLD
$.removeCookie('name');
//NEW
Cookies.remove('name');

Your script path is the problem. Try this cdn:

<script type="text/javascript" src="https://cdnjs.cloudflare./ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
发布评论

评论列表(0)

  1. 暂无评论