title: update cart from view page using ajax in magento 1.9
body: <p>Add to cart works fine on view page. Items are updated dynamically. But Update cart doesnt update header cart items. Items are updated after refresh.</p>
  
  <p>checkout/cart/item/configure/updatecart.phtml</p>
  
  <pre><code>&lt;?php $_product = $this-&gt;getProduct(); ?&gt;
  &lt;?php $buttonTitle = $this-&gt;__('Update Cart'); ?&gt; 
  &lt;?php if($_product-&gt;isSaleable()): ?&gt;
  &lt;div class="add-to-cart"&gt;
      &lt;?php if (!$_product-&gt;isGrouped()): ?&gt;
      &lt;div class="qty-wrapper"&gt;
          &lt;label for="qty"&gt;&lt;?php echo $this-&gt;__('Qty:') ?&gt;&lt;/label&gt;
          &lt;input type="text" pattern="\d*" name="qty" id="qty" maxlength="12" value="&lt;?php echo $this-&gt;getProductDefaultQty() * 1 ?&gt;" title="&lt;?php echo $this-&gt;__('Qty') ?&gt;" class="input-text qty" /&gt;
      &lt;/div&gt;
      &lt;?php endif; ?&gt;
      &lt;div class="add-to-cart-buttons"&gt;
          &lt;button type="button" title="&lt;?php echo $buttonTitle ?&gt;" class="button btn-cart" onclick="productAddToCartForm.submit(this)"&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $buttonTitle ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;
          &lt;span id='ajax_loader' style='display:none'&gt;&lt;img src='&lt;?php echo $this-&gt;getSkinUrl('images/opc-ajax-loader.gif')?&gt;'/&gt;&lt;/span&gt;
          &lt;?php echo $this-&gt;getChildHtml('', true, true) ?&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  
  
  <p>view.phtml</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
  //&lt;![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;
          // Start of our new ajax code
          if (!url) {
              url = jQuery('#product_addtocart_form').attr('action');
          }
          url = url.replace("checkout/cart","ajax/index"); // New Code
          var data = jQuery('#product_addtocart_form').serialize();
          data += '&amp;isAjax=1';
          jQuery('#ajax_loader').show();
              try {
                  jQuery.ajax({
                    url: url,
                    dataType: 'json',
                    type : 'post',
                    data: data,
                    success: function(data){     
                        console.log(data);
                          jQuery('#ajax_loader').hide();
                          alert(data.message);
                          //console.log(url);
                          if(jQuery('#gd_total')){ 
                               jQuery("#gd_total").html( jQuery(data).find('#gd_total'));
                          }
  
                          if(jQuery('.count')){
                               var count=jQuery(data.toplink).find('.count').text();
                               jQuery(".count").html(count);
                                jQuery(".skip-cart").removeClass("no-count");
                          }      
                          if(jQuery('.minicart-wrapper')){ 
                             // jQuery('.header-minicart').replaceWith(data.toplink);
                             var cart=jQuery(data.toplink).find('.minicart-wrapper').html();
                               jQuery(".minicart-wrapper").html(cart);
                          }                             
  
                    }
              });
              }  catch (e) {
          }
          // End of our new ajax code
          this.form.action = oldUrl;
          if (e) {
              throw e;
          }
      }
  }.bind(productAddToCartForm);
  productAddToCartForm.submitLight = function(button, url){
          if(this.validator) {
              var nv = Validation.methods;
              delete Validation.methods['required-entry'];
              delete Validation.methods['validate-one-required'];
              delete Validation.methods['validate-one-required-by-name'];
              if (this.validator.validate()) {
                  if (url) {
                      this.form.action = url;
                  }
                  this.form.submit();
              }
              Object.extend(Validation.methods, nv);
          }
      }.bind(productAddToCartForm);
  //]]&gt;
  &lt;/script&gt;
  </code></pre>