let's say the backend_page_to_update_db.php page take around 5 secs to update the data into DB.
Question #1 :
$(".update_btn").on("click",() => {
$.post('backend_page_to_update_db.php',
{
value1 : value1,
value2 : value2
}, function(result) {
$(".some_class").text("done with updating database");
});
});
My question is, upon clicking on the update_btn button I closed the page with in 2 secs or so.
Will the DB gets updated with POST data since the page is triggered or will it get cancelled as well.
Presuming it gets updated in DB irrespective we wait for it or not, Please check the same for the below code as well.
Quesiton #2 :
$(".update_btn").on("click",() => {
var main = async () => {
var fun2 = (value) => {
new Promise(async (resolve) => {
value = value + 1;
$.post('backend_page_to_update_db_2.php',
{
value : value,
}, function(result) {
console.log("fun2 done");
});
return resolve(fun1(value));
});
};
var fun3 = () => {
new Promise(async (resolve) => {
value = 1;
$.post('backend_page_to_update_db_3.php',
{
value : value,
}, function(result) {
console.log("fun3 done");
});
return resolve(fun2(value));
});
};
var fun1 = (value) => {
new Promise(async (resolve) => {
value = value + 1;
$.post('backend_page_to_update_db_1.php',
{
value : value,
}, function(result) {
console.log("fun1 done");
});
return resolve(value);
});
};
fun3();
};
main();
});
Presuming I closed the window after i see the fun3 and fun2 get executed through console, and closed the window. i.e., The fun1 query got triggered and the window wasn't opened till it gets executed. Will the fun1 query get executed..?
Presuming I closed the window after i see the fun3 alone in the console and closed the window, i.e., The fun2 might got triggered but the fun1 wasn't, which can cause issues with data in DB, In these kinda scenarios we need to delete the recent updates or insert that happened recently using reject or failure in the promise. But How..?
Note: Edits to this query are welcomed.