I am using ajaxForm
to send data to php file which runs in background, and some js functions will be checking if php file is running asynchroniously. So in case of some failure(internet/electricity went off), I want my user be able to retry the last form submission. So I found some ajax retry functions as this, best way to retry ajax but it is on the same ajax request, i need to be able to retry my ajax from another function. Is it even possible? Given that I am storing passed values in form.
$(document).ready(function(){
$('#form').ajaxForm({
target: '#ajax-response',
success: function(){
initAjaxCheck();
}
});
Check();
});
Here's js scripts:
function Check(){
$.ajax({
type:"POST",
url:"ajax.php",
data:{'flag':'Check'},
success:function(result){
if (result=="1") {
initAjaxCheck();
}
}
});
}
function initAjaxCheck(){
$.ajax({
type:"POST",
url:"ajax.php",
data:{'flag':'initProcCheck'},
success:function(data){
if (data=="1"){
timerCheck=setInterval(function(){
ajaxCheck(timerCheck);
},1000);
} else { //unsuccessful
var toRepeat = confirm ("Last try was unsuccessful. Retry?");
if (toRepeat){alert("retry");} else {alert("cancel");}
}
}
});
}
So if my user press RETRY, I should have to retry my ajaxForm submission.