You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
67 lines
2.4 KiB
function show_error(message){ |
|
$('#error_alert').slideDown(500); |
|
$('#error_alert').delay(2000).slideUp(); |
|
if (message) |
|
$('#alert_error_text').text(message) |
|
} |
|
|
|
function show_success(message){ |
|
$('#success_alert').slideDown(500); |
|
$('#success_alert').delay(2000).slideUp(); |
|
if (message) |
|
$('#alert_success_text').text(message) |
|
} |
|
|
|
function validate_length(val, dest_len){ |
|
if(val.length < dest_len){ |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
$(document).ready(function(){ |
|
$('body').append('<div id="error_alert" class="alert alert-danger" role="alert" style="position: fixed; top: 50px; left: 10%; right: 10%; z-index: 9999; display: none;">Ошибка<br><small id="alert_error_text"></small></div>'); |
|
$('body').append('<div id="success_alert" class="alert alert-success" role="alert" style="position: fixed; top: 50px; left: 10%; right: 10%; z-index: 9999; display: none;">Успех<br><small id="alert_success_text"></small></div>'); |
|
$('#fio').on("input", function(){ |
|
console.log($('#fio').val()); |
|
}); |
|
|
|
$("#form_submit").click(function(){ |
|
$(this).children(".spinner-border").removeClass('d-none'); |
|
$(this).attr("disabled", true); |
|
message = {} |
|
|
|
|
|
if(!(validate_length($('#fio').val(), 3))) |
|
{ |
|
show_error('Введите ФИО', false); |
|
$(this).children(".spinner-border").addClass('d-none'); |
|
$(this).removeAttr("disabled"); |
|
return; |
|
} |
|
|
|
$.each($('.tg_input'), function(e) { |
|
message[$(this).prop("id")] = $(this).val(); |
|
}); |
|
console.log(message); |
|
$.ajax({ |
|
type: "post", |
|
url: "/form_submit", |
|
processData: false, // tell jQuery not to process the data |
|
contentType: false, // tell jQuery not to set contentType |
|
async: true, |
|
data: JSON.stringify(message), |
|
success: (data) => { |
|
$(this).children(".spinner-border").addClass('d-none'); |
|
$(this).removeAttr("disabled"); |
|
console.log(data); |
|
show_success("Данные сохранены!") |
|
}, |
|
error:function (jqXHR, exception) { |
|
$(this).children(".spinner-border").addClass('d-none'); |
|
$(this).removeAttr("disabled"); |
|
show_error('Что-то пошло не так', false) |
|
} |
|
}); |
|
}); |
|
}); |