JavaScript How to use ajax add to cart for related products magento

I'm trying to use ajax add to the cart in related products but I don't know how to get link to the each related products?

I would like to use ajax and not be redirected to the cart page when I click add to the cart. For the main product this is working well. But for related is adding the main product or adding related product but redirect me to the cart.

 <?php endif; ?>
                <a target='_blank' href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(350); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
                </a>

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

Can I use

productAddToCartForm.submit(this)

But what to pass inside submit?

This is the add to cart code

<script type="text/javascript">
    //<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(button, url) {
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;

                if (url) {
                   form.action = url;
                }
                var e = null;
                if (!url) {
                    url = jQuery('#product_addtocart_form').attr('action');
                }
                url = url.replace("checkout/cart","ajaxcart/index"); // New Code
                var data = jQuery('#product_addtocart_form').serialize();
                data += '&isAjax=1';
                jQuery('#loading-mask').show();
                try {
                    jQuery.ajax({
                        url : url,
                        dataType : 'json',
                        type : 'post',
                        data : data,
                        success : function(data) {
                            jQuery('#loading-mask').hide();
                            if(data.status == 'ERROR'){
                                alert(data.message);
                            }else{
                                if(jQuery('.top-links .right-links')){
                                    jQuery('.top-links .right-links').replaceWith(data.toplink);
                                }
                                jQuery('#after-loading-success-message').show();
                            }
                        }
                    });
                } catch (e) {
                }                
                this.form.action = oldUrl;
                if (e) {
                    throw e;
                }
            }
        }.bind(productAddToCartForm);
    //]]>
    </script>
Answer:1

I am beginner in typescript programming not able to set property interface type so please guide me about that. interface addition { num1: number; num2: number; add(num1:number, num2:...

I am beginner in typescript programming not able to set property interface type so please guide me about that. interface addition { num1: number; num2: number; add(num1:number, num2:...

I have a HTML import element, which is a DOM element, imported via: <link rel="import" src="element.html"> Now i want to update the custom element without reloading the site. //example method ...

I have a HTML import element, which is a DOM element, imported via: <link rel="import" src="element.html"> Now i want to update the custom element without reloading the site. //example method ...

  1. polymer update element
  2. polymer refresh element
  3. polymer change element property

I'm trying to write a curried function dissoc, that takes in a prop and an object and removes the key and its value from the object. Here is the code that works: const dissoc = prop => obj => {...

I'm trying to write a curried function dissoc, that takes in a prop and an object and removes the key and its value from the object. Here is the code that works: const dissoc = prop => obj => {...

  1. javascript object destructuring rename
  2. javascript object destructuring default value
  3. javascript object destructuring nested
  4. javascript object destructuring assignment
  5. javascript object destructuring alias
  6. javascript object destructuring undefined
  7. javascript object destructuring reassign
  8. javascript object destructuring rest
  9. javascript object destructuring null
  10. javascript object destructuring array
  11. javascript object destructuring into new object
  12. javascript object destructuring argument
  13. javascript object destructuring constructor
  14. javascript object destructuring function arguments
  15. javascript object destructuring remove property
  16. javascript object destructuring parameters
  17. javascript object destructuring function parameters
  18. javascript object destructuring dynamic key
  19. javascript object destructuring deep
  20. javascript object destructuring example

I would like to know how to disable unselected checkboxes using jQuery. The goal is to disable the unselected checkboxes if the number of selected checkboxes is greater than or equal to 3. $('....

I would like to know how to disable unselected checkboxes using jQuery. The goal is to disable the unselected checkboxes if the number of selected checkboxes is greater than or equal to 3. $('....

  1. disable unchecked checkbox jquery
  2. disable unchecked checkbox javascript
  3. unchecked disabled checkbox