title: Shopify Order form Ajax loops twice
body: <p>I have a Ajax order form on a product page. When you click the <code>#submit-table</code> button it will display a drop down menu showing the updated cart information, including updated quantities and prices together with the products that have just been added.</p>
  
  <p>This is an image of my problem (only the green correct item should be showing up):</p>
  
  <p><a href="https://i.stack.imgur.com/pa39o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pa39o.png" alt="enter image description here"></a></p>
  
  <p>This is my code so far but its firing twice thus duplicating products, whats going wrong with it?</p>
  
  <pre><code>$(document).ready(function () {
  $("#submit-table").click(function(e) {
      e.preventDefault();
      //array for Variant Titles
      var toAdd = new Array();
    var qty;
  
      for(i=0; i &lt; length; i++){
          toAdd.push({
              variant_id: $("#variant-"+i).val(),
              quantity_id: $("#quantity-"+i).val() || 0
          });
      }
  
      function moveAlong(){
          if (toAdd.length) {
              var request = toAdd.shift();
              var tempId= request.variant_id;
              var tempQty = request.quantity_id;
              var params = {
                  type: 'POST',
                  url: '/cart/add.js',
                  data: 'quantity='+tempQty+'&amp;id='+tempId,
                  dataType: 'json',
                  success: function(line_item) {
  
            jQuery.getJSON('/cart.js', function(cart, variant, item, line_item) {
              $('nav .customer-wrap ul li.basket span').text(cart.item_count);
              $( '&lt;li class="c-1"&gt;&lt;a href="{{ item.url }}" title="View product"&gt;  &lt;div class="qc-thumb"&gt;&lt;img src="{{ item.product.featured_image.src | product_img_url: 'thumbnail' }}" alt="{{ item.title }}" class="wk-variant-image" /&gt;&lt;/div&gt;  &lt;div class="qc-details"&gt;&lt;p&gt;{{ product.title }}&lt;/p&gt;  &lt;p&gt;Qty:' + tempQty + '&lt;/p&gt;&lt;/div&gt;&lt;/a&gt;&lt;/li&gt;' ).prependTo( ".basket-quick-view" );
            });
  
            console.log("success!");
            setTimeout(function () {
              $('nav .customer-wrap ul li.basket ul.basket-quick-view').removeClass('variant-added');
            }, 3000);
  
            moveAlong();
  
                  },
                  error: function() {
                      console.log("fail");
                      moveAlong();
                  }
              };
              $.ajax(params);
          }
          else {
              //document.location.href = '/cart';
          }
      };
  
    jQuery.getJSON('/cart.js', function(cart, variant) {
      $('nav .customer-wrap ul li.basket span').addClass('product-added');
      $('li.empty').hide();
      $('nav .customer-wrap ul li.basket ul.basket-quick-view').addClass('variant-added');
    });
  
      moveAlong();
  });
  });
  </code></pre>