Jquery cookie nasıl ayarlanır?

3 Cevap php

Ben sayfayı yenileyerek sonra değerini almak böylece cookie kurmak istiyorum.

Ben aşağıdaki kodu yazdım Ama çerez ayarlamak mümkün değilim.

$j("#add_to_cart_action").click(function(e) {
      $j.em.cart.addSelectedTitle();
    });

$j.em.cart.addSelectedTitle = function() {
  var addcartitemindx = $j("body").data("selected_title").product_id;
  var indx = $j("body").data("selected_title").cindex;
  var addcartitemtitle = $j("body").data("selected_title").ctitle;
  if ($j('input#chkout_'+addcartitemindx).length > 0) {
    alert('Shopping Cart Notification:\n "'+addcartitemtitle+'" is already added.');
    return false;
  }
  $j.cookie("example",addcartitemtitle);
  alert( $j.cookie("example") );
  //$j('#checkout_form ul').prepend('<li><input type="checkbox" id="chkout_'+addcartitemindx+'" class="added-item" value="'+addcartitemindx+'"/><a href="javascript:$j.em.cart.TriggerCartItem('+addcartitemindx+');">'+addcartitemtitle+'</a></li>');
  $j('#checkout_form ul').prepend('<li><input checked="true" type="checkbox" id="chkout_'+addcartitemindx+'" name="product[]" class="added-item" value="'+addcartitemindx+'"/><a href="javascript:$j.em.cart.TriggerCartItem('+indx+');">'+addcartitemtitle+'</a></li>');

  $j.em.cart.setCartDisplay();
};

3 Cevap

Javascript çerez ayarlamak için:

document.cookie = 'name=value; expires=Thu, 1 Dec 2009 20:00:00 UTC; path=/'

Ayrıca jquery plugin var.

You code looks fine to me. You can try to add options like this:

$.cookie('example', 'cookie-value', { path: '/', expires: 1 });

Bu değişmemişse jquery.cookie çekirdek içinde değildir. Eğer dosya yüklemek için emin mi? yani

<script src="js/jquery.cookie.js" type="text/javascript"></script>

Also cookies have to be enabled, obviously. You can see if your cookie gets set in ff 3.5 if you go to Tools->Preferences->Privacy and click on "remove individual cookies". There's a list of cookies ordered by domain.

Onun jQuery kadar hatırlayabildiğim gibi, bir üçüncü taraf plug-in kullanmadan çerezleri desteklemediği fazlalaştı.