如何通过jquery ajax永久更改html元素,以便在刷新页面后保留?

Im a beginner in codeigniter and am trying to make sort of an ecommerce website.

Now whenever a user clicks on the "Add to cart" button in my view, i use jquery ajax to send a request to a controller function which returns two variables count(total items in cart) and total(the total value of items in cart) as a string and then i modify a div with class .cart to simply display a string containing the two variables.

$(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

        }
    });

    });
})

But the string doesnt remain when i refresh the page or go to another page. i want the change made through jquery permanent and remain their regardless where the user navigates in the website. I need direction on how to accomplish this. if i need to save it to my database, then what and how to go about it

use post method like

$.post('url',{var:value,var2:value},function(data){
  $('.cart').html(data);
});

$('.cart').html(data); or $('.cart').load(data);