开发者

Don't get value when refreshing the page in jquery

When I click on link the value displayed correctly.But when I refresh the page i don't get this value.

I have written below code

$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_tit开发者_JAVA百科le").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('#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();
};

I want to store addcartitemtitle in cookie so that i can restore so please give me the syntax to write it in jquery.


If you mean Items in cart are not displayed on refreshing then you need either store them on user's side using cookies or store on server when adding to cart so that on refreshing you can restore them.

you need to identify the which items belong to cart on which machine, you can use cookie to identify machine if you store selected items on server. If the your users have to register and login to select items then you can put items in cart into a db and associate them with user id. Now wherever user logs in you can get items associated with his/her id and display in cart.


I think if i understand your problem well enough.. You don't get that value after the refresh because you don't save it anywhere... If you want javascript to remember some given values, you need to put it in a cookie or something.. Or you need to use ajax or and give it to a serverside programming language to do this for you

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜