0

ドラッグアンドドロップを使用してカートに商品を追加したい。ドロップ関数で、Ajax関数を呼び出して、カートに商品を追加します。

url変数には、商品に基づくチェックアウトカートの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" );
  }
});
});

およびindexcontrollerコードには次のものが含まれます:-

$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 ;

商品はカートに追加されますが、応答がなく、1つの商品をドロップした後、カートにそれ以上商品をドロップできないため、Ajax呼び出しは完了しません。私を助けてください

4

2 に答える 2

0

使用できます

 jquery.post(url,callback).
于 2013-02-13T06:44:59.440 に答える
0

成功コールバックを使用.....

成功のコールバック関数には、返されたデータが渡されます。これは、応答の MIME タイプに応じて、XML ルート要素、テキスト文字列、JavaScript ファイル、または JSON オブジェクトになります。また、応答のテキスト ステータスも渡されます。

jQuery.get(url, function(data) {
   // data is the response from the server..
   console.log(data);
});
于 2013-02-13T06:47:29.953 に答える