2010-06-23 67 views
5

我试图用Jquery进行类别更改& Php。我没有问题。我的问题是,当更新事件被调用时,它返回2个结果。 1个拖拽父项的结果,1个删除父项的结果。我想只打电话给父母的身份证。这是我的脚本:Jquery Sortable Update Event只能调用一次?

$("#gallery ul").sortable({ 
    connectWith: '.dropBox', 
    opacity: 0.35, 
    scroll: true, 
    scrollSensitivity: 100, 
    //handle: '.move', 
    helper: 'clone', 
    containment:'#gallery', 
    accept:'#gallery > .photo', 
    revert: true, 
    update: function(event, ui){ 
     params = 'c=' + $(this).attr('id') + '&id=' + ui.item.attr('id'); 

     $.ajax({ 
      type: 'POST', 
      url: 'processData.php', 
      data: params, 
      error:function(){ 
       alert("Error!"); 
      }, 
      success:function(data){ 
       $("#serverResponse").html(data); 
      } 
     }); 
    } 
}).disableSelection(); 

你能帮助我吗?

回答

7

使用updatestopreceive事件,例如

$(function() { 
    position_updated = false; //flag bit 

    $(".sortable").sortable({ 
     connectWith: ".sortable", 

     update: function(event, ui) { 
      position_updated = !ui.sender; //if no sender, set sortWithin flag to true 
     }, 

     stop: function(event, ui) { 
      if (position_updated) { 

       //code 

       position_updated = false; 
      } 
     }, 

     receive: function(event, ui) { 
      // code 
     } 

    }).disableSelection(); 
}); 
3

ui.sender只存在于第二个回调。

$(".sortable").sortable({ 
    connectWith: ".sortable", 
    update: function (evt, ui) { 

     // just ignore the second callback 
     if(ui.sender == null){ 

      // call ajax here 

     } 


    }, 
    receive: function (evt, ui) { 

     // called after the first 'update' 
     // and before the second 'update' 
     // ui.sender is always exists here 

    } 

}).disableSelection(); 
+0

+1优秀。这是一个令人头疼的问题。谢谢 – 2011-10-03 05:20:06

0

只是这样做:

update: function(event, ui) { 
      if(ui.sender) { 
      // Your actual code 
      } 
     },