Search code examples
jquerybuttonhyperlinkajaxify

Activate a function/hyperlink, but stay on the same page


I would like to make "add to cart" button work in a way so that a person stays on the same page once they click on it, but that the items still gets added to their cart. How can I make that? Does it have to be ajaxified, and if yes then how? Here is the button code itself:

<div id="custom-buttons">
<div id="custom-cart">
<a href="ShoppingCart.asp">
<input class="vCSS_input_addtocart" type="image"
src="/v/vspfiles/templates/248/images/buttons/btn_addtocart.gif" 
name="btnaddtocart" alt="Add to cart" border="0" 
data-image-path="/v/vspfiles/templates/248/images/buttons/btn_addtocart.gif"/>
</a>
</div>

Solution

  • The question you need to ask yourself is whether you're fine with the page reload after a new cart item is added, or not.

    1. If not, it would need to be done with Ajax:
    2. If you don't mind the page reload you could send new item data to (for example) a PHP function, store the item in the session and redirect to the page the request came from.