我有一個頁面上加載模式的按鈕。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火災?
兩個ajax調用的目的是什麼? – guest271314
哪裏是模態代碼?你所展示的只是ajax代碼 – charlietfl