제출할 때 양식을 처리하는 jQuery ajax 스크립트가 있습니다. 그러나, 나는 ajax 요청 중에 "processing ..."과 "done"등을 추가하는 몇 가지 콜백을 가지고있다. 그러나 스크립트가 모두 끝나면 스크립트에서 다시 edit button
을 추가하여 양식을 다시 사용할 수 있지만 버튼을 두 번 추가합니다.이 콜백이 두 번 실행되는 이유는 무엇입니까?
이 아약스 요청이 시작되는 곳, 코멘트 당신이
$.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
에 두 번 경고 함).
의견이 있으십니까?
'parent '클래스에'message'클래스가 여러개 있습니까? HTML 코드없이 말하기는 어렵습니다. – AppleGrew