$(document).ready(function() { $('#addToCart').click(function() { AddToCart(); }) $('.cartProductRemove').click(function() { if (confirm('Are you sure?')) { RemoveFromCart($(this)); } }) $('.updateCart').click(function() { if (confirm('Are you sure?')) { UpdateCart(); } }) }); function RemoveFromCart(x) { $.ajax({ type: 'POST', url: 'https://www.businessnhmagazine.com/Components/Newsarticle/Assets/AJAX/RemoveFromCart.php', dataType : 'text', // data type data : 'id='+x.attr('rel'), success: function(msg){ var ret = msg.split(';;'); if (ret[0] == 1) { $(x).parent().parent().hide(); if (ret[1] == 0) { $('.notification-number').addClass('number0'); } else { $('.notification-number').removeClass('number0'); } $('#currentTotal').html(ret[2]); $('.notification-number').html(ret[1]); setTimeout( function(){ window.location.href = 'https://www.businessnhmagazine.com/cart'; }, 500); } else { //console.log(ret[1]) //$('.addtocart-message').html('
'+ret[1]+'
'); } } }); } function AddToCart() { $.ajax({ type: 'POST', url: 'https://www.businessnhmagazine.com/Components/Newsarticle/Assets/AJAX/AddToCart.php', dataType : 'text', // data type data : 'quantity='+$('#Quantity').val()+'&id='+$('#IssueID').val(), success: function(msg){ var ret = msg.split(':'); if (ret[0] == 1) { $('.notification-number').removeClass('number0'); $('.notification-number').html(ret[1]); $('.addtocart-message').html('
'+$('#addToCart').attr('rel')+' Added To Your Cart.
Continue Shopping
Click Here To Checkout
'); } else { console.log(ret[1]) $('.addtocart-message').html('
'+ret[1]+'
'); } } }); } function UpdateCart() { var vals = $('#cartProducts').find('select, textarea, input').serialize(); $.ajax({ type: 'POST', url: 'https://www.businessnhmagazine.com/Components/Newsarticle/Assets/AJAX/UpdateCart.php', dataType : 'text', // data type data : vals, success: function(msg){ var ret = msg.split(':;:'); if (ret[0] == 1) { setTimeout( function(){ window.location.href = 'https://www.businessnhmagazine.com/cart'; }, 1000); } else { } } }); }