How to force update of some values when using Javascript window.history.back ()?

2

Is it possible to force update of some values of my View even when I use window.history.back() of Javascript? My example:

In my layout, I have a cart icon with the number of items inside it. When I add an item to the cart with this code:

function AddCartItem(obj) {
obj.SelectedResolutionID = $('input[name=ImageResolutionID]:checked').val();

$.ajax({
    method: "POST",
    url: "/Ajax/AddCart",
    data: JSON.stringify(obj),
    contentType: "application/json; charset=utf-8",
    dataType: "json"
})
    .done(function (obj) {
        if (obj.response) {
            setTimeout(function () { window.history.back() }, 500);
        }
    });
}

and return to the previous page using window.history.back() as written in the code above. However, this command possibly recovers from the cache the previous page, and the icon with the number of items does not update! is it possible for me to force this update and keep the command window.history.back() ?

I use ASP.NET MVC5, the number of items in my cart comes from a cookie control class, follow the code:

<li>@CartCookieController.ReturnCartProductsCount()</li>
    
asked by anonymous 08.11.2017 / 19:00

1 answer

0

You can store the information using cookies.

<input id="backbutton" type="button" value="Back" onClick="atualizarCarrinho()"/>

function atualizarCarrinho()
{
 document.cookie = name+"=index%3d1; expires=whenever;path=/";
 window.history.back()
}
    
17.11.2017 / 17:03