I am using sweetalert2 queue to show all modals after each other. Every modal have a confirm button (some with an action coming from a database). If the user click on the first confirm button, the next modal shows up, and so on. After all modals are displayed the confirm buttons with there actions are saved in database. But is it possible to do an action after every modal is displayed?
Here is my code:
var modals = [];
$.ajax({
type: "POST",
url: "index/popup_notification_collect",
dataType: 'json',
data: {user_id: user_id},
success: function(res) {
if(res.type == 'error'){
//alert(res.message);
}
if(res.type == 'success'){
var arr = [];
//console.log(res.data);
$.each(res.data, function(index, value) {
var obj = JSON.parse(value);
var buttonClass = obj["confirmButtonClass"];
var test2 = buttonClass.split('_');
arr.push({
id: test2[0],
userid: test2[1],
//button: buttonClass,
type: test2[2]
});
console.log(obj);
modals.push(obj);
});
//console.log(modals);
swal.queue(modals).then((result) => {
if (result.value) {
console.log(result);
var m = 0;
$.each(result.value, function(index, value) {
var id = arr[m].id;
var userid = arr[m].userid;
var type = arr[m].type;
console.log(id+'-'+userid+'-'+type);
//Update database if type is received
if(type == 'received') {
$.ajax({
type: "POST",
url: "index/popup_notification_received",
dataType: 'json',
data: {id: id, userid: userid},
success: function(data) {
if(data.type == 'error'){
console.log(data.message);
}
if(data.type == 'success'){
//alert(data.message);
}
}
});
}
//Update database if type is all_round
if(type == 'allround') {
$.ajax({
type: "POST",
url: "index/popup_notification_all_round",
dataType: 'json',
data: {id: id},
success: function(data) {
if(data.type == 'error'){
console.log(data.message);
}
if(data.type == 'success'){
//alert(data.message);
}
}
});
}
m++;
});
}
});
}
}
});