salve io utilizzo questo javascript per realizzare un ajax:
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser== "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(file,action) {
http.open("get", file+"?action="+action, false);// sincrona!
http.send(null); //qua si ferma in attesa di risposta
//ora posso testare il readyState e prendere il responseText
if(http.status == 200){
var response = http.responseText;
//document.write(response);
var splitString = response.split("#####");
var text1 = splitString[0];
var text2 = splitString[1];
document.getElementById(text2).innerHTML = text1;
}else {
alert("Si è verificato un errore: \n" + http.status + " - " + http.statusText);
}
}
l'ajax viene richiamato con un select in questo modo:
<select name="SCOMP1_<? echo $value;?>" onchange="sndReq('pagina.php',this.value)">
<? arrayOption($arrayS,$_POST[$SCOMP],"","");?>
</select>
la pagina "pagina.php" che gestisce l'ajax è la seguente
if($_GET['action']!=NULL){
switch($_GET['action']){
case 0: ?>
<div class="sinistro">Sottocategoria *</div>
<div class="destro" >
<select name="sottocategoria">
<? arrayOptionIdUTF8($arraySottoMenu,$_SESSION['sottocategoria'],"Seleziona",""); ?>
</select>
</div>
<?
break;
case 1:?>
<div class="sinistro">Sottocategoria *</div>
<div class="destro" >
<select name="sottocategoria">
<? arrayOptionIdUTF8($arraySottoMenu,$_SESSION['sottocategoria'],"Seleziona",""); ?>
</select>
</div>
<?
break;
}
?>
<? } ?>#####catPP
Io vorrei che nell'attesa che l'ajax faccia il suo lavoro si visualizzi un'immagine loader.gif, ma non riesco a visualizzarla. come devo fare?