Ste*_*ins 1 javascript ajax jquery callback
我有一个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]");
});
Run Code Online (Sandbox Code Playgroud)
完整的脚本在这里.
关于它的一切工作,除了最后一次回调发生两次(它将提醒stop两次).
有什么想法吗?
| 归档时间: |
|
| 查看次数: |
2546 次 |
| 最近记录: |