Ajax电话没有得到任何响应&无法在购物车中第二次丢弃产品

时间:2013-02-13 06:39:08

标签: jquery ajax magento magento-1.7 jquery-ui-draggable

我想使用拖放功能将产品添加到购物车中下降。在drop函数中,我调用Ajax函数将产品添加到购物车:

url变量包含基于产品的结帐购物车网址。

jQuery(function() {
jQuery(".category-products" ).accordion();
jQuery(".product-name" ).draggable({
  appendTo: "body",
  helper: "clone"
});
jQuery(".block-content ol" ).droppable({
  activeClass: "ui-state-default",
  hoverClass: "ui-state-hover",
  accept: ":not(.ui-sortable-helper)",
  drop: function( event, ui ) {
    jQuery( this ).find( ".placeholder" ).remove();
    var url =  ui.draggable.attr('id');
    jQuery.get(url, function(data) {
          // data is the response from the server..
          if(data.status == 'ERROR'){
    alert(data.message);
    }
          console.log(data); 
      });
         url += 'isAjax/1';
    url = url.replace("checkout/cart","draggableproduct/index");
    try {
        jQuery.ajax( {
            url : url,
            dataType : 'json',
            success : function(data) { 
                if(jQuery('.block-cart')){
            jQuery('.block-cart').replaceWith(data.sidebar);
        }
        if(jQuery('.header .links')){
            jQuery('.header .links').replaceWith(data.toplink);
        }
            }
        });
    } catch (e) {
    alert(e);
    }
        jQuery( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );   
  }
}).sortable({
  items: "li:not(.placeholder)",
  sort: function() {
    // gets added unintentionally by droppable interacting with sortable
    // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
    jQuery( this ).removeClass( "ui-state-default" );
  }
});
});

并且索引控制器代码包含: -

$this->loadLayout();
                $toplink = $this->getLayout()->getBlock('top.links')->toHtml();
                $sidebar_block = $this->getLayout()->getBlock('cart_sidebar');
                Mage::register('referrer_url', $this->_getRefererUrl());
                $sidebar = $sidebar_block->toHtml();
                $response['toplink'] = $toplink;
                $response['sidebar'] = $sidebar;
                                    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
        return ;

产品已添加到购物车中,但Ajax调用未完成,因为我没有得到任何响应,在丢弃1个产品后,我无法将更多产品放入购物车。请帮帮我

2 个答案:

答案 0 :(得分:0)

您可以使用

 jquery.post(url,callback).

答案 1 :(得分:0)

使用成功回调.....

  

成功回调函数传递返回的数据,该数据将是XML根元素,文本字符串,JavaScript文件或JSON对象,具体取决于响应的MIME类型。它还传递了响应的文本状态。

jQuery.get(url, function(data) {
   // data is the response from the server..
   console.log(data);
});