Developer forum

Forum » Ecommerce - Standard features » Anybody have an example of adding a product top a minicart using ajax, without reloading the page?

Anybody have an example of adding a product top a minicart using ajax, without reloading the page?

Hans Ravnsfjall
Hans Ravnsfjall
Reply

The minicart is placed in <div class="vognur"></div> -

And i am trying to add mulitple products to the cart, and then reload ?d=22 into the <div class="vognur"></div>

 

Here is what i have so far in the javacsript function being called on clicking add to cart.

 

        var prodid=prod1; (this is ofcourse a dynamic field)
           var amount=2;( this is ofcourse a dynamic field)
    
         
           var ajstring="ProducID="+prodid+"&Quantity="+amount+"&CartCMD=addMulti";
           
           
           $.ajax({
           type: "POST",
           url: "http://lyfta.dw9.dynamicweb-cms.com/Default.aspx?ID/?id=22",  
           data: ajstring,
           success: function(result){
            $(".vognur").html(result);
        }});

 

But it is not working. The ajax part is working fine, and something gets loaded into the div - but products are not added.

 

What am i missing? Does anyone have any documentation on this? CanĀ“t find anything here on the doc.portal - and more than half the search results lead to dead links on this portal.

 

/Hans
       


Replies

 
Nicolai Pedersen
Reply

Rapido uses AJAX - but in a very different way.

But, I can see you use the addMulti cart command - that takes the parameters in a different format (you need a counter as an indicator). So try changing it to "add" instead and see if that helps... See more here: https://doc.dynamicweb.com/documentation-9/ecommerce/orders/shopping-cart#2948

BR Nicolai

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

ok thank you for your reply Nicolai.

Can i post the data it to any page, or do i have to put some module other than the cart module on the page i post to?

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Problem solved

the ajax call should look like this

 
           $.ajax({
           type: "POST",
           url: "http://mypage.dw9.dynamicweb-cms.com?id=22",  
           data: {productid: PROD1, Quantity: 1, cartcmd: 'add'},
           success: function(data){
            $( "#topcart" ).load( "http://mypage.dw9.dynamicweb-cms.com?id=22" );
        }});

 

/Hans

 

You must be logged in to post in the forum