【发布时间】:2011-09-04 08:25:47
【问题描述】:
我正在使用下面的代码通过 Ajax 调用保存多个可排序列表的顺序,并且由于某种原因,它每次单击都会运行多次调用。如果#resedit div 中有两个列表,我会收到 4 到 8 个警报。
我不明白为什么 ajax 调用或警报会被多次发出......在 .each 函数中发生的唯一事情是构建一个变量,并且在发生其他任何事情之前它们已完全关闭。
谁能看出我哪里出错了?
var listorder = '';
$('#resedit').children().each(function(index) {
if ($(this).css('display') != 'none' && $(this).attr('id') != '') {
listorder = listorder + $(this).attr('id') + ', ';
$(this).children().each(function(indexchildren) {
if ($(this).css('display') != 'none' && $(this).attr('id') != '') {
listorder = listorder + $(this).attr('id') + ', ';
placeholder = indexchildren;
}
});
}
});
var data = {
action : 'save_res',
security : '<?php echo $saveres_nonce; ?>',
resorder : listorder,
resumeslug : $('#res-dash-select').val(),
}
jQuery.post(ajaxurl, data, function(response) {
alert(response);
return;
});
});
【问题讨论】:
-
末尾有一个额外的
});,这让我相信其中包含更多代码。是否还有其他东西包含在内或者只是不需要})。
标签: javascript jquery nested each