non lo puoi fare così
o fai tutto lato client oppure usi ajax
ho fatto una cosa del genere tempo fa te l'ho adattata alla tua richiesta
crei tre file
prova.php
Codice PHP:
<html>
<head>
<title>Prova</title>
<script type="text/javascript" src="prova.js"></script>
</head>
<body>
<div id="divout">
</div>
</body>
</html>
prova.js
Codice PHP:
var currentPage = "";
function AjaxRefresh(id){
var xmlHttp;
var ciccio=0;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("AJAX not found!");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if (currentPage!=xmlHttp.responseText){
var risposta=xmlHttp.responseText;
//var risposta='ciao';
if(risposta[0]!='')
document.getElementById('divout').innerHTML=document.getElementById('divout').innerHTML+'
'+risposta;
//currentPage=xmlHttp.responseText;
//alert(id);
id=risposta;
//alert(risposta);
if(risposta!='BOOM')
{
setTimeout('AjaxRefresh('+id+')',1000);
}
}
}
}
//alert('we');
//var id=0;
xmlHttp.open("GET","richiedimsg.php?id="+id);
xmlHttp.send(null);
}
window.onload=function(){
setTimeout('AjaxRefresh(0)',1000);
}
richiedimsg.php
Codice PHP:
<?php
$id=$_GET['id'];
if($id<=2)
{
echo ($id+1);
}
else
{
echo "BOOM";
}
?>
poi dal browser richiama prova.php