2016-01-16 49 views
0

我有一个页面上加载模式的按钮。jquery删除旧功能,并在点击处理程序

在这种模式下,我显示数据。

该数据可以包含例如某个表的5个条目 当条目被删除时,数据被刷新。添加条目时也是如此。

现在,当我通过单击外部并重新打开它来关闭模式时。第一个模态附加的功能仍然存在并且正在触发。 所以,如果我添加一个条目。这样做的ajax和脚本被解雇/被调用两次。

代码:

  $(document).on('click','.remove_team',function(){ 
       var tournament_id = $(this).data('tourn'); 
       $.ajax({ 
        url :'./organisations/waiting_list/team_assignement.php', 
        type :'POST', 
        data : { 
         action : 'remove_team', 
         team_id : $(this).data('team'), 
         tourn : $(this).data('tourn') 
        }, 
        success : function(){ 
         LoadParticipantList(tournament_id); 
        } 
       }) 
      }) 
      function LoadParticipantList(tournament){ 
       $.ajax({ 
        url :'./organisations/waiting_list/team_assignement.php', 
        type :'POST', 
        data : { 
         action :'fetch_team_participants', 
         tournament : tournament 
        },success : function(res){ 
         res = jQuery.parseJSON(res);   
         $("#counter_"+tournament).html(res.count);    
         $("#div_"+tournament).html(res.teams); 
        } 
       }) 
      } 

的是换掉一个单击处理程序的正确方法,然后再直接添加它,以便在AJAX火灾?

+0

两个ajax调用的目的是什么? – guest271314

+0

哪里是模态代码?你所展示的只是ajax代码 – charlietfl

回答

0

你可以做的是增加你的模式弹出外的单击事件。这个点击事件停止,你不希望有治疗的...

$('documents').bind('click', function(e) { 
    if($(e.target).closest('#your_modal_id').length == 0) { 
     //click happened outside the modal popup : stopping treatments 
    } 
}); 

还添加了停止传播事件,以避免不必要的治疗方法来运行...

$('#your_modal_id').click(function(event){ 
event.stopPropagation(); 
}); 

希望它可以帮助

0

jQuery .off方法将完成这项工作。

相关问题