Developer forum
E-mail notifications
Add a product to the cart through ajax and jquery
I found an artical on the old forum explaining how to emptying the basket with Ajax through jQuery:
On my solution it only hides the div.smallcart. It dosnt empty the cart. So when I leave the page the cart is still there.
So what am I doing wrong?
If I can get this to work it would properly solve my real problem on adding a product to the cart without the page reloading.
/Rasmus
<!--
function emptybasketajax(message) {
var emptyurl = '/default.aspx?cartcmd=emptycart';
var confirmation = confirm(message);
if (confirmation) {
$.<b style="color:black;background-color:#a0ffff">ajax</b>({
url: emptyurl,
async: false
});
// Removing the cart from the page with jquery
$('.smallcart').remove();
// Removing the cart from the page by reloading the page
window.location.reload();
};
}
-->
<!--
<a href="javascript:emptybasketajax('Do you want to <b style="color:black;background-color:#99ff99">empty</b> your basket?');">- <b style="color:black;background-color:#99ff99">Empty</b> basket</a>
-->
Replies
Hi Rasmus,
You forgot to remove styles from ajax call.
Was: $.<b style="color:black;background-color:#a0ffff">ajax</b>({
Shoud be: $.ajax({
<script language="javascript">
function emptybasketajax(message) {
var emptyurl = '<!--@Ecom:Cart.EmptyCartLink-->';
var confirmation = confirm(message);
if (confirmation) {
$.ajax({
url: emptyurl,
async: false
});
// Removing the cart from the page with jquery
$('#orderdetails').remove();
// Removing the cart from the page by reloading the page
//window.location.reload();
};
}
</script>
<a href="javascript:emptybasketajax('Do you want to empty your basket?');"><b style="color:black;background-color:#99ff99">Empty</b> basket</a>
Kind Regards
Zhukovskiy Yury
I've just posted an article on my blog regarding managing the shopping cart using AJAX:
Managing your shopping cart using AJAX
-- Pavel
Hi guys,Hi Pavel, looks great! :-) But...
I've just posted an article on my blog regarding managing the shopping cart using AJAX:
Managing your shopping cart using AJAX
-- Pavel
It would be really great if this could somehow be added to the Dynamicweb core instead. I think all partners have customers who cannot afford the extra 300kr a month, which it costs to host a custom solution. :-)
And you can do it already - by using a dedicated layout template in your ajax request.
Can you please explain a little more on this? Maybe an example request...
I've allready seen this one, but I can't seem to make it work with Designs & Layouts...: http://websiteudvikler.dk/post/howto-implement-an-ajax-based-shopping-experience-in-dynamicweb-ecommerce.html
You must be logged in to post in the forum