How to force the updating of some values when I use the Javascript window.history.back()?

Asked

Viewed 71 times

2

It is possible to force updating some values of my View even when using the 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 above code. However, this command may cache the previous page, and the icon with the number of items does not update ! it is 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 basket comes from a cookie control class, follows the code:

<li>@CartCookieController.ReturnCartProductsCount()</li>
  • 1

    You can do this by creating a client-side storage form, such as localStorage and calling a JS function that will update the number on the cart icon whenever a page opens, either by history.back() or not.

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()
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.