I am not to familiar with AJAX/Javascript so I am having a hard time doing something simple.
I am trying to clear the cart using Shopify's AJAX API before someone adds an item to the cart.
My code currently looks like this:
<script>
function clearcart()
{
var my_button=$('input.addToCart');
my_button.on('click',function(){
$.ajax({
type: "POST",
url: '/cart/clear.js',
data: '',
success: success,
dataType: 'json',
success: function() {
return Shopify.clear();
},
error: function(XMLHttpRequest, textStatus) {
/* error code */
}
});
return false;
});
}
</script>
<input type="submit" name="add" value="Try Now" class="addToCart" onclick="clearcart();" "javascript:window.location='/cart' return false"/>