양식 제출을 위해 JS 코드를 따라했습니다. submitForm
함수에 양식 제출을 계속 했으므로 selector
및 action
값을 submitForm
함수에 전달하여 여러 양식에 사용할 수 있습니다. .JS : 콜백 함수가 실행되지 않습니다.
function submitForm(selector, action, onComplete) {
var response
$(selector).submit(function (e) {
e.preventDefault();
var data = $(this).serializeArray();
$.ajax({
type: 'POST',
url: action,
data: data,
dataType: 'json',
a
sync: false,
success: function (data) {
response = data;
}
});
});
return response;
}
submitForm(".lform", "user.php", function (response) { // Callback function
// Doing necessary stuff
});
위 코드에서 콜백 기능이 실행되지 않고 있습니다. 그 이유는 무엇입니까? 그리고 내부 콜백 함수는 다음 코드가 있습니다.
location.reload(); // To refresh the total DOM,
$(".c_form").dialog({
closeOnEscape: false,
title: title,
modal: true,
close: function() {
$(this).dialog('destroy').hide();
}
});
페이지를 새로 고침 한 후 표시 대화 상자를 표시 할 수 있습니까?
'var response'는 AJAX 요청이 요청을 완료하기 전에 함수가 이미 반환되었으므로 초기화되지 않습니다. – Aiias