title: Ajax add to cart is not adding products to the cart
body: <p>*<em>Ajax add to cart is not updating the product to the shopping cart upon onclick action checkout/continue in the popup and then it redirects to the URL <a href="http://hostip.com/checkout/cart/" rel="nofollow">http://hostip.com/checkout/cart/</a> *</em></p>
  
  <p><em>I had used this JavaScript</em></p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
      function setAjaxData(data,iframe){
              if(data.status == 'ERROR'){
                  alert(data.message);
              }else{
                  if(jQuery('.block-cart')){
                      jQuery('.block-cart').replaceWith(data.sidebar);
                  }
      //            if(jQuery('.header .links')){
      //                jQuery('.header .links').replaceWith(data.toplink);
      //            }
                  if(jQuery('.cart-top-container')){
                      //jQuery('.cart-top-container').empty();
                      jQuery('.cart-top-container').replaceWith(data.toplink);
                  }
                  var targetUrl='&lt;?php echo Mage::getUrl('onestepcheckout') ?&gt;';
                  jQuery( "#dialog-confirm" ).dialog({
                      resizable: false,
                      //height:140,
                      modal: true,
                      buttons: {
                          "Checkout": function() {
                              window.location.href = targetUrl;
                              //jQuery(this).dialog( "close" );
                          },
                          "Continue Shopping": function() {
                              jQuery(this).dialog( "close" );
                          }
                      }
                  });
              }
          }
          function setLocationAjax(url,id){
              url += 'isAjax/1';
              url = url.replace("checkout/cart","ajax/index");
              jQuery('#ajax_loader'+id).show();
              try {
                  jQuery.ajax( {
                      url : url,
                      dataType : 'json',
                      success : function(data) {
                          jQuery('#ajax_loader'+id).hide();
                          setAjaxData(data,false);          
                      }
                  });
              } catch (e) {
              }
          }
      &lt;/script&gt;
  
  
  
  
  *The form to submit is*
  
  &lt;form action="&lt;?php echo $this-&gt;getSubmitUrl($p) ?&gt;" method="post" id="product_addtocart_form"&lt;?php if ($p-&gt;getOptions()): ?&gt; enctype="multipart/form-data"&lt;?php endif; ?&gt;&gt;
                          &lt;div class="home-prouduct-details"&gt;
                              &lt;?php $pid = $p-&gt;getId(); ?&gt;
                              &lt;?php $prod = Mage::getModel('catalog/product')-&gt;load($pid);  ?&gt;
                              &lt;?php $html= $prod-&gt;getShortDescription(); ?&gt;
                              &lt;?php                          
                                 $str = $html;
                                 $matches = array();
                                 preg_match_all('#&lt;div[^&gt;]*&gt;(.*?)&lt;/div&gt;#', $str, $matches);
  //                               print_r($matches[1][0]);
                              ?&gt;
                              &lt;a class="prod-name" href="&lt;?php echo $prod-&gt;getProductUrl(); ?&gt;"&gt;&lt;?php echo $prod-&gt;getName(); ?&gt;&lt;/a&gt;
                              &lt;div class="prod-img"&gt;
                                  &lt;a href="&lt;?php echo $prod-&gt;getProductUrl() ?&gt;" title="&lt;?php echo $this-&gt;stripTags($this-&gt;getImageLabel($prod, 'small_image'), null, true) ?&gt;" class="product-image"&gt;
                                      &lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($prod, 'small_image')-&gt;resize(285,172); ?&gt;" width="285" height="175" alt="&lt;?php echo $this-&gt;stripTags($this-&gt;getImageLabel($prod, 'small_image'), null, true) ?&gt;" /&gt;
                                  &lt;/a&gt;
                              &lt;/div&gt;
                              &lt;div class="home-price-button"&gt;
                                  &lt;?php $almost_gone_qty=$this-&gt;htmlEscape($prod-&gt;getData('almost_gone_qty')); ?&gt;
                                  &lt;?php $qtyStock = Mage::getModel('cataloginventory/stock_item')-&gt;loadByProduct($prod)-&gt;getQty(); ?&gt;
                                  &lt;?php if (!$this-&gt;hasOptions() &amp;&amp; strtotime($prod-&gt;getDealEndDate())&gt;= Mage::getModel('core/date')-&gt;timestamp(time())):?&gt;
                                      &lt;div style="clear:both;"&gt;&lt;/div&gt;
                                      &lt;div class="add-to-box"&gt;
                                          &lt;?php if($prod-&gt;isSaleable() &amp;&amp; $qtyStock &gt; $almost_gone_qty){ ?&gt;
                                              &lt;p class="availability out-of-stock"&gt;
                                                  &lt;a onclick="setLocationAjax('&lt;?php echo Mage::helper('checkout/cart')-&gt;getAddUrl($prod); ?&gt;',&lt;?php echo $prod-&gt;getId();?&gt;)" title="Add To Cart"&gt;
                                                      &lt;img src="&lt;?php echo $this-&gt;getSkinUrl('images/steamy.png'); ?&gt;" title="Add To Cart" alt="Add To Cart" width="285" /&gt;
                                                  &lt;/a&gt;
                                              &lt;/p&gt;
                                              &lt;?php } else if($qtyStock &lt;= $almost_gone_qty &amp;&amp; $qtyStock!=0){?&gt;
                                                  &lt;p class="availability out-of-stock"&gt;
                                                      &lt;a onclick="setLocationAjax('&lt;?php echo Mage::helper('checkout/cart')-&gt;getAddUrl($prod); ?&gt;',&lt;?php echo $prod-&gt;getId();?&gt;)" title="Almost Gone"&gt;
                                                          &lt;img src="&lt;?php echo $this-&gt;getSkinUrl('images/almostgone.png'); ?&gt;" title="Almost Gone" alt="Almost Gone" width="285" /&gt;
                                                      &lt;/a&gt;
                                                  &lt;/p&gt;
                                              &lt;?php } else{ ?&gt;
                                                  &lt;p class="availability out-of-stock"&gt;
                                                      &lt;a href="&lt;?php echo Mage::getBaseUrl(); ?&gt;sold-out" title="Sold Out"&gt;
                                                          &lt;img src="&lt;?php echo $this-&gt;getSkinUrl('images/soldout.png'); ?&gt;" width="285" /&gt;&lt;?php //echo $this-&gt;__('Out of stock') ?&gt;
                                                      &lt;/a&gt;
                                                  &lt;/p&gt;
                                              &lt;?php } ?&gt;
                                              &lt;span id='ajax_loader&lt;?php echo $prod-&gt;getId()?&gt;' style='text-align: center; display:none'&gt;&lt;img src='&lt;?php echo $this-&gt;getSkinUrl('images/opc-ajax-loader.gif')?&gt;'/&gt;&lt;/span&gt;
                                      &lt;/div&gt;                                    
                                  &lt;?php else : ?&gt;
                                      &lt;p class="deal-has-ended"&gt;
                                          &lt;a href="&lt;?php echo Mage::getBaseUrl(); ?&gt;sold-out" title="Sold Out"&gt;
                                              &lt;img src="&lt;?php echo $this-&gt;getSkinUrl('images/deal_ended.png'); ?&gt;" width="285" /&gt;
                                          &lt;/a&gt;
                                      &lt;/p&gt;                                
                                  &lt;?php endif; ?&gt;
                                      &lt;?php echo $this-&gt;getChildHtml('addto') ?&gt;
                                      &lt;?php //echo $this-&gt;getChildHtml('extra_buttons') ?&gt;
                              &lt;/div&gt;
                              &lt;div class="home-price"&gt;
                                  &lt;div class="home-prices"&gt;
                                      &lt;?php 
                                          echo Mage::helper('core')-&gt;currency($prod-&gt;getPrice());
                                      ?&gt;    
                                  &lt;/div&gt;
                                  &lt;?php if($matches[1][1] !=""){ ?&gt;
                                      &lt;div class="home-save"&gt;
                                          &lt;?php
                                              $savings = $matches[1][1];
                                              $savings = str_ireplace('Rs.', '&amp;#8377;', $savings);
                                              $savings = str_ireplace('Rs', '&amp;#8377;', $savings);
                                              echo $savings;
                                          ?&gt;
                                          &lt;?php //print_r($matches[1][1]); ?&gt;
                                          &lt;div class="home-saver"&gt;
                                              savings
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;?php } ?&gt;
                                  &lt;div class="deal-endtime"&gt; 
                                      &lt;?php 
                                                      echo "&lt;div id='cdcontainer_".$prod-&gt;getId()."' class='cdcontainer'&gt;&lt;/div&gt;";
                                                      $dealEndDate = $prod-&gt;getDealEndDate();
                                                      $dealEndDateParts = explode(" ", $dealEndDate);
                                                      $targetDateParts = explode("-", $dealEndDateParts[0]);
                                                      $year = $targetDateParts[0];
                                                      $month = $targetDateParts[1];
                                                      $date = $targetDateParts[2];
  
                                                      $month_array = array(
                                                              "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
                                                      );
                                                      $month = $month_array[$month-1];
  
                                                      $targetDate = "$month $date, $year ".$dealEndDateParts[1];
                                                      $timer_text = Mage::getStoreConfig('homedeals/basic_settings/cd_display_text');
                                                      $timer_end_text = Mage::getStoreConfig('homedeals/basic_settings/cd_end_text');     
                                                      //echo $timer_end_text;
                                                      //echo date("Y-m-d H:i:s"); echo "&lt;br/&gt;";
                                                      //echo $dealEndDate;
                                                      if($dealEndDate &lt;= date("Y-m-d H:i:s")){
                                                      ?&gt;
                                                      &lt;script type="text/javascript"&gt;
                                                              var launchdate_&lt;?php echo $prod-&gt;getId(); ?&gt;=new cdLocalTime("cdcontainer_&lt;?php echo $_product-&gt;getId(); ?&gt;", "server-php", 0, "", "", "&lt;?php echo '&lt;span&gt;&lt;h1 style=color:red;&gt;Deal has ended - 00:00:00&lt;/h1&gt;&lt;/span&gt;' ?&gt;&lt;?php //echo $timer_text; ?&gt;", "&lt;?php echo $timer_end_text; ?&gt;", "&lt;?php echo $prod-&gt;getId(); ?&gt;");
                                                              launchdate_&lt;?php echo $prod-&gt;getId(); ?&gt;.displaycountdown("hours", formatresults2);
                                                      &lt;/script&gt;
                                                      &lt;?php   }else { ?&gt;
                                                      &lt;script type="text/javascript"&gt;
                                                              var launchdate_&lt;?php echo $prod-&gt;getId(); ?&gt;=new cdLocalTime("cdcontainer_&lt;?php echo $prod-&gt;getId(); ?&gt;", "server-php", 0, "&lt;?php echo $targetDate?&gt;", "&lt;?php print date("F d, Y H:i:s", Mage::getModel('core/date')-&gt;timestamp(time()))?&gt;", "&lt;?php echo $timer_text; ?&gt;", "&lt;?php echo $timer_end_text; ?&gt;", "&lt;?php echo $prod-&gt;getId(); ?&gt;");
  
                                                              launchdate_&lt;?php echo $prod-&gt;getId(); ?&gt;.displaycountdown("hours", formatresults2);
                                                      &lt;/script&gt;
                                                      &lt;?php } ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div id="dialog-confirm" style="display:none;"&gt;
                              &lt;?php echo $prod-&gt;getName();?&gt; added to your cart Successfully.
                          &lt;/div&gt;
                          &lt;/form&gt;
  </code></pre>