/* Обновление игры через AJAX */
$('.saveBtnInModal').click(function (e) {
var formData = new FormData($("#editFormModal")[0]);
$.ajax({
type: 'POST',
url: 'games/updateGameInfo',
data: formData,
async: false,
beforeSend: function () {
// до отправки данных, можно поставить например гифку loading
swal.showLoading();
},
success: function (data) {
// удача
swal({
title: 'Данные игры успешно обновлены!',
type: 'success',
timer: 3000
}).then(
function () {
},
// handling the promise rejection
function (dismiss) {
if (dismiss === 'timer') {
}
}
);
$("#gamesTable").load(location.href + ' #gamesTable');
$('.modal').modal('hide')
},
error: function (data) {
// если ошибка, показываем ошибку
swal({
title: 'Ошибка! Что-то не так!',
type: 'error',
timer: 10000
}).then(
function () {
},
// handling the promise rejection
function (dismiss) {
if (dismiss === 'timer') {
}
}
);
},
complete: function () {
// после завершения запроса, с любым исходом. Убираем гифку загрузки
},
cache: false,
contentType: false,
processData: false
});
e.preventDefault();
});
$(".editBtnModal").each(function () {
$(this).click(function (e) {
var id_games = $(this).data('value');
$.ajax({
type: 'GET',
url: "games/getGameInfo",
data: {id_games: id_games},
beforeSend: function () {
// до отправки данных, можно поставить например гифку loading
swal.enableLoading();
},
success: function (data) {
// удача
var editFormModal = $('#editFormModal');
editFormModal.find('#id_games').val(data.id_games);
editFormModal.find('#game_name').val(data.game_name);
editFormModal.find('#game_desc').val(data.game_desc);
editFormModal.find('#steam_link').val(data.steam_link);
editFormModal.find('#id_developer').val(data.id_developer);
swal.close();
$('.modal').modal('show')
},
error: function (data) {
// если ошибка, показываем ошибку
swal({
title: 'Ошибка! Что-то не так!',
type: 'error',
timer: 10000
}).then(
function () {
},
// handling the promise rejection
function (dismiss) {
if (dismiss === 'timer') {
}
}
);
},
complete: function () {
// после завершения запроса, с любым исходом. Убираем гифку загрузки
},
});
$('#exampleModalLabel').text('Редактировать');
$('#editFormModal').show();
$('#formAddNewGame').hide();
e.preventDefault();
});
});
Кнопка
<button type="button" data-value="34" class="btn btn-primary
editBtnModal">Редактировать</button>