![](/img/trans.png)
[英]How do I create an HTML element that remains on the page and is unaffected by scroll?
[英]How do i make changes to an html element through jquery ajax permanent so it remains after refreshing the page?
我是Codeigniter的初學者,正在嘗試建立一個電子商務網站。
現在,每當用戶單擊我視圖中的“添加到購物車”按鈕時,我都使用jquery ajax向控制器函數發送請求,該函數返回兩個變量count(購物車中的商品總數)和total(購物車中商品的總價值) )作為字符串,然后我將.cart類的div修改為僅顯示包含兩個變量的字符串。
$(document).ready(function(){
$("#addtocart").click(function(){
var id = $("#product_id").val();
var qty = $("#quantity").val();
$.ajax({
url: "<?php echo base_url('cart/addtocart'); ?>",
data: {id: id , qty:qty },
type: 'POST',
success: function(name) {
$(".cart").html(name); //This is the div where show number of items in cart and total value of cart
}
});
});
})
但是當我刷新頁面或轉到另一頁面時,字符串不會保留。 我希望通過jquery所做的更改永久保留,並且無論用戶在網站中的導航位置如何,都保留它們。 我需要有關如何完成此操作的指導。 如果我需要將其保存到數據庫中,那么該如何處理
使用像
$.post('url',{var:value,var2:value},function(data){
$('.cart').html(data);
});
$('.cart').html(data); or $('.cart').load(data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.