Cart page not refresh after adding product in the cart by ajax api

hello

i have this script i want to added the product in cart by ajax api but cart page should not be refresh tell me the solution for this i am using public app and injecting the script file in the shopify

data = {

“id”: 37298631540894

}

$.ajax({
type: ‘POST’,
url: ‘/cart/add.js’,
data: data,
dataType: ‘json’,
success: function(result) {
console.log(result) ;
window.location.href = ‘/cart’;
}
});

window.location.href = ‘/cart’; in the success method tells the browser to go to that url(hypertextreference) when the ajax request succeeds.

The browser will even navigate to that page if it’s already on that page using window.location.href