开发者

JQuery - removing entry from a cookie

I have a cookie which I would like to read then remove one entry from it based in the widget ID.

if (thisWidgetSettings.removable) {
            $('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
                /* STOP event bubbling */
                e.stopPropagation();    
            }).click(function () {
                if(confirm('This widget will be removed, ok?')) {

        $.ajax({
            type: "get",
            url: "/controllers/widget.php",
            data: {
                method: "remove",
                widgetID:thisWidget.id,
                   },
                   dataType: "json",

                });

        var mycookie = $.cookie("mypreferences");

//remove based on id here


as suggested...

var cookieName = 'myCookie'; var cookie = $.cookie("preferences");

                        var cookie = cookie.split('|');

                         $(cookie).each(function(i开发者_如何学运维ndex){

                               var thisCookieData = this.split(',');


                            alert(thisCookieData);


                              });


use split() to get individual elements from your cookie and than loop through them, and remove it. and then combine the rest of your entries and save it.

split reference:

http://www.w3schools.com/jsref/jsref_split.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜