Io uso questo e puo' essere richaiamo sia in get che post(nell esempio get)
Codice PHP:
function ahah(url,target,delay, function_extra, post){
var type = "GET";
if(window.XMLHttpRequest){
var req=new XMLHttpRequest();
}else if(window.ActiveXObject){
var req=new ActiveXObject("Microsoft.XMLHTTP");
}
if(req!=undefined){
if(post)
type = "POST";
req.open(type,url,true);
if(post){
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
req.onreadystatechange=function(){
if(req.readyState!=4){
}else{
ahahDone(req, url,target,delay, function_extra);
}
};
req.send(post);
}
}
function ahahDone(req, url,target,delay, function_extra){
if(req.readyState==4)
{
alert('fai qualcosa durante il caricamento.....');
if(req.status==200)
{
if(target)
{
document.getElementById(target).innerHTML='';
document.getElementById(target).innerHTML=req.responseText;
}
if (function_extra){
setTimeout(function_extra, 100);
}
}
}
}
qusto sopra e' il file ahah.js da includere nell <head> della pagina
Nella pagina html(o php cmq):
Codice PHP:
<head>
<script type="text/javascript" src="ahah.js"></script>
<script>
function prova()
{
ahah('index.php?prova=1', 'idtag');
}
</script>
</head>
<body>
[url="#"]click[/url]
<div id="idtag">prima del caricamento</div>
.....
passi al metodo l'ulr con tutti i parmetri che ti servono e il secondo e' l'id del div da refreshare
In index.phpcome da url passata)
Codice PHP:
if($_GET['prova']){
echo 'dopo caricamento';
}
Vedrai che ci sara' un alert e in quella parte di codice gli dirai tu cosa fare.. ad esempio visualizzare il div con l immagine che vuoi per poi nasconderlo a fine caricamento
EDIT: dove vedi if(req.status==200) nel codice, li ha finito l esecuzione e prima di modificare l'innerHTML nascondi l'immagine