0

I am trying to show a confirmation message in jQuery Dialog after adding a product into cart using AJAX.

I have tried using jQuery to achieve this. But it reloads the page(Although it adds the product to cart). I want to show a dialog as soon as a product is added into cart.

I am using Drupal Commerce Kickstart Distribution which comes with AJAX add to cart functionality. This is the code that I am using in my custom module that shows up dialog. (The dialog is shown when a user clicks on "add to cart" button, however, the page gets reloaded as well).

(function ($) {
    // all my code here.
    Drupal.behaviors.a_mods = {
        attach: function(context) {
            $('.dahdah').click( function(){
                $('#success-message').dialog();     
            })
        }};
})(jQuery);

If this is not possible to achieve this functionality this way, then please point me in the right direction. Thanks.

InspiredCoder
  • 394
  • 6
  • 22
  • What reloads the page? The AJAX or another functionality? –  Mar 19 '15 at 23:29
  • I think when I target the submit button using jQuery, it redirects to the same page after adding product into cart instead of initiating an AJAX request. – InspiredCoder Mar 20 '15 at 00:29

1 Answers1

0

You can try add return false; after dialog will be shown, you should have

$('#success-message').dialog();
return false;
Max
  • 711
  • 5
  • 13