[英]ajaxComplete with getJSON causing loop
I am using ajaxComplete to run some functions after dynamic content is loaded to the DOM. 在将动态内容加载到DOM之后,我正在使用ajaxComplete运行一些功能。 I have two separate functions inside ajaxComplete which uses getJSON. 我在使用getJSON的ajaxComplete内部有两个单独的函数。
How do I get around this? 我该如何解决?
I'm attaching a small part of the code. 我只附加一小部分代码。 If the user has voted, clicking the comments button will cause the comments box to open and close immediately. 如果用户已投票,则单击评论按钮将使评论框立即打开和关闭。
$(document).ajaxComplete(function() {
// Lets user votes on a match
$('.btn-vote').click(function() {
......
$.getJSON(path + 'includes/ajax/update_votes.php', { id: gameID, vote: btnID }, function(data) {
......
});
});
// Connects a match with a disqus thread
$('.btn-comment').click(function() {
var parent = $(this).parents('.main-table-drop'), comments = parent.next(".main-table-comment");
if (comments.is(':hidden')) {
comments.fadeIn();
} else {
comments.fadeOut();
}
});
});
Solved the problem by checking the DOM loading ajax request URL 通过检查DOM加载ajax请求URL解决了该问题
$(document).ajaxComplete(event,xhr,settings) {
var url = settings.url, checkAjax = 'list_matches';
if (url.indexOf(checkAjax) >= 0) { ... }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.