Developer forum

Forum » Templates » Add a product to the cart through ajax and jquery

Add a product to the cart through ajax and jquery

Rasmus Samsig
Reply
Hi,

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

 
Yury Zhukovskiy
Reply

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








 
Jacob Jensen
Reply
The header on this post says: "Add a product to the cart through ajax and jquery" - did you get this to work... I mean adding the product to the cart without page reload, and the quantity and total amount being updated in the "small cart"?
 
Pavel Volgarev
Reply
Hi guys,

I've just posted an article on my blog regarding managing the shopping cart using AJAX:

Managing your shopping cart using AJAX

-- Pavel

 
Jacob Jensen
Reply
Hi guys,

I've just posted an article on my blog regarding managing the shopping cart using AJAX:

Managing your shopping cart using AJAX

-- Pavel

Hi Pavel, looks great! :-) But...
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. :-)

 
Nicolai Høeg Pedersen
Reply
Custom solutions does not cost extra... Except free/express which is DKK 50/month.

And you can do it already - by using a dedicated layout template in your ajax request.

 
Jacob Storgaard Jensen
Reply
Hi Nicolai,
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