2

This question already has an answer here:

I need an add to cart and buy now button. It is working fine but when I click buy now button, nothing is happening and after a couple of seconds the page is redirecting to the cart page. I need to redirect the page once I click buy now button

Here is the code I am using in addtocart.phtml

 <button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/cart/') ?>')"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>

<script>
 function setcheckoutLocation(location,chkout)
 {
  jQuery.ajax({
                type:"GET",
                url:location,
                success:function(data){
                     window.location.href = chkout;
                }
             });
}
</script>

marked as duplicate by Amit Bera, Marius Aug 25 '16 at 7:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

When you click the button, there's an Ajax call being done. This takes some time and after that it is redirecting. If this Ajax call is not being done, then the product will not be added to the cart.

I think you mean that this is a problem in user experience. You could solve this by making the button change, once you have clicked it, so the user knows something is happening. There are tons of examples of buttons with loading effects: https://google.com/search?q=button+loading&tbm=isch

Not the answer you're looking for? Browse other questions tagged or ask your own question.