SORU
22 EYLÜL 2009, Salı


Nasıl jQuery ile geri al çerez set/?

Kurabiye adlı ayarlama 'test' ve ' . değeri ^strong>1'?

Ve özellikle, nasıl atanır?

CEVAP
22 EYLÜL 2009, Salı


Bakın eklentisi:

https://github.com/carhartl/jquery-cookie

Sonra da yapabilirsiniz:

$.cookie("test", 1);

Silmek için:

$.removeCookie("test");

Ayrıca, cookie on gün belirli bir sayıda (10) bir zaman aşımı süresi ayarlamak için:

$.cookie("test", 1, { expires : 10 });

Eğer bu seçenek atlanmış dolarsa, o zaman çerezi oturum çerezi olur, ve tarayıcıdan çıktığında silinir.

Tüm seçenekleri karşılamak için:

$.cookie("test", 1, {
   expires : 10,           //expires in 10 days

   path    : '/',          //The value of the path attribute of the cookie 
                           //(default: path of page that created the cookie).

   domain  : 'jquery.com',  //The value of the domain attribute of the cookie
                           //(default: domain of page that created the cookie).

   secure  : true          //If set to true the secure attribute of the cookie
                           //will be set and the cookie transmission will
                           //require a secure protocol (defaults to false).
});

Çerez değerini okumak geri:

var cookieValue = $.cookie("test");

Eğer çerez mevcut olan farklı bir yol üzerinde oluşturulursa, path parametresi belirlemek isteyebilirsiniz:

var cookieValue = $.cookie("test", { path: '/foo' });

GÜNCELLEME (Nisan 2015):

Belirtildiği gibi aşağıya yorum, takım üzerinde çalışan orijinal eklenti vardır çıkarılmış bir WordPress kullanmak bağımlılık yeni bir proje (https://github.com/js-cookie/js-cookie) aynı işlevselliği ve genel sözdizimi olarak jquery sürümü. Görünüşe göre orijinal eklenti olsa bir yere gitmiyor.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Keith Anthe

    Keith Anthe

    26 NİSAN 2011
  • Paste Magazine

    Paste Magazi

    28 AĞUSTOS 2008
  • PaulGBelliveau

    PaulGBellive

    5 Mart 2009