I have a page that users will click a update link and once they land on the page it will tell the server to grab data from a API and takes a few minutes. The problem is I don't wan't to have to keep refreshing the page to send the user back once it has updated.
Is there a jQuery function that will check a PHP file every 10 seconds and if the PHP files says example yes it will the redirect them.
Sorry I'm new with jQuery.
Just use GET
:
function detectChange(){
$.get('file.php', function(data) {
if(data == 'example'){
document.location = 'http://example.com';
}
});
setTimeout(function(){ detectChange(); }, 10000);
}
setTimeout(function(){ detectChange(); }, 10000);
Where the 10000
is 10 seconds in milliseconds. Check out the documentation for more info.
The set interval function lets you specify a function to run every x miliseconds. Param 1 is the function, param 2 is miliseconds.
You can use $.get, $.post, or $.ajax. Look up jquery docs or follow example below.
setInterval(function(){
$.get("phpFile.php",{[insert your params here]},function(serverResponse){
if(serverResponse ==="yes")
window.location = "redirect_file.php";
}
},10000);