Thanks @sampoyigi . It works like charm!
If any want to use it. Below is the code I used.
for css overlay loading spinner: https://codepen.io/MattIn4D/pen/LiKFC
add a div with id 'cartloading' with style display none;
function removeCart(menu_id, row_id, quantity) {
$('#cartloading').css('display', 'block'); // runs when function is called.
$.ajax({
url: js_site_url('cart_module/cart_module/remove'),
type: 'post',
data: 'menu_id' + menu_id + '&row_id=' + row_id + '&quantity=' + quantity,
dataType: 'json',
success: function(json) {
$('#cartloading').css('display', 'none'); //removes the css overlay
updateCartBox(json)
}
});
}
You can add it on any ajax function calls.