Shopping cart contains urls with total key like
Cart value is <span id="cart-status" >1805.32</span>
<ul>
<li><a href='/Store/Category/Products?user=ADMIN&total=1805.32'>product1</a></li>
<li><a href='/Store/Category/Products?user=ADMIN&total=1805.32'>product2</a></li>
<li><a href='/Store/Category/Products?user=ADMIN&total=1805.32'>product3</a></li>
</ul>
For proper caching in browser cart current value total=1805.32 is added to every url.
It contains also add to cart form whixh uses ajax and does not refresh page:
<form class='tdBorder js-addtocart-form' method="post">
<span>
<input type='hidden' name="product" value="CAR2" />
<input class='amount' name="quantity" type="number" value="1" />
</span>
<input type="submit" value="Add to cart" class='btn btn-xs btn-success' />
</form>
<script>
var request;
$(function () {
$(".js-addtocart-form").submit(function (event) {
if (request) {
request.abort();
}
var $form = $(this);
var $inputs = $form.find("input, select, button, textarea");
var serializedData = $form.serialize();
request = $.post('@Url.Action("AddToCart", "Store")',
serializedData, function (response) {
$("#cart-status").text(response.Total);
var xx = $form[0].quantity;
.always(function () {
$inputs.prop("disabled", false);
});
return false;
});
});
Cart value in page is updated in Store/AddToCart result using
$("#cart-status").text(response.Total)
How to update a elements total keys with response.Total in page ?
Bootstrap 3, jquery, ASP.NET MVC4 are used
Any information you store on a web page is unreliable, you should not trust it. I hope you are using it just for some kind of cache on web page only, if your server is also using total value coming from this link, then stop, you are doing it wrong.
For you answer you can modify total parameter by this code:
function updateLink(val){
$("link selector").each(function(i,v){
var href = $(v).attr("href");
if(href){
href = href.replace(/total=[^&]+/,"total="+val);
$(v).attr("href", href);
}
});
}
you need to modify link selector
and give it some selector so that it can select all such links and call this method with new total value.