我有一个jQuery ajax脚本来处理提交表单。但是,我有一个回调,以在ajax请求期间添加“处理...”和“完成”等。但是,完成后脚本应该将edit button
添加回人员可以再次使用该窗体,但是它将添加按钮两次。这个回调为什么发射两次?
这是Ajax请求开始的地方,该意见将帮助您按照
$.ajax({
url: "../ajax/update_site_info.php?id=" + $('[name="site_id"]').val() + "&field=" + $(parent).children("input").attr("name") + "&value=" + $(parent).children("input").val(),
cache: false,
success: function(response){
//alert('success');
// On success, fade out the "Saving..."
$(parent).children('.message').fadeOut(150, function(){
//alert('message');
// Remove the save button (submit button)
$(parent).children(".jUpdateSave").remove();
// Add "Saved!"
$(parent).append('<span class="message">' + response + '</span>');
// Let "Saved!" linger for a while before it fades out
$(parent).children('.message').delay(1500).fadeOut(250, function(){
//alert("stop"); // THIS IS WHERE THINGS HAPPEN TWICE
// Put the edit button back
$(parent).append('<a class="jUpdate"><img src="images/shared/icon_edit.png" width="16" height="12" alt=""></a>');
// Remove the "Saved1" message
$(parent).children('.message').remove();
});
});
}
}).error(function(){
$(".message").text("There was an error proccessing your request. [0]");
});
完整的脚本是here。
除了最后一次回调发生两次(它会提示stop
两次)之外的所有工作。
有什么想法?
在class'message'的'parent'下有多个孩子吗?没有HTML代码很难说。 – AppleGrew