Con ajax. Prova prima com'è poi cambia 2000 in 10000 (10 secondi) nella funzione start();
Con 2000 devi essere reindirizzato alla pagina test9352b.php. Con 10000 (o comunque un valore maggiore di 4) dovresti vedere comparire la scritta Ok.
test9352c.php impiega 4 secondi per completarsi.
Codice PHP:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.t {border:1px black}
.a {background-color:yellow}
.b {background-color:green}
.r {background-color:blue}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var valoreFinale="";
function callPage() {
var res = Math.random();
var src = "";
var id = "";
var param = '&r='+res;
$.ajax({
url : 'test9352c.php',
type : 'POST',
data : param,
dataType : 'html'
}).done(function(html) {valoreFinale = html;$("#pippo").html("Ok");}) ;
}
function start() {
callPage();
setTimeout(
function ()
{
if (valoreFinale=="")
{
window.location = 'test9352b.php'
}
}
,2000);
// 2000 = 2 secondi
}
</script>
</head>
<body>
<div id="pippo"></div>
<button onclick="start()"/>Clicca</button>
</body>
</html>
test9352b.php
Codice PHP:
<?php
print "tempo scaduto";
test9352c.php
Codice PHP:
<?php
// simulazione di una pagina che si carica in 4 secondi
$d1 = new DateTime('NOW');
$end = false;
while (!$end) {
print 'testo<br/>';
$now = new DateTime('NOW');
$diff = $now->diff($d1);
if ($diff->s >= 4) {
$end = true;
}
}