Ho realizzato una funzione in AJAX che interroga un file php che a sua volta effettua una query ad un database MySql per restituirmi il valore più alto di un ID.
Il mio problema nasce quando devo utilizzare il valore numerico che restituisce la funziona AJAX...ho già testato con un alert che la funzione mi restituisce esattamente il valore dell'ID.
La funzione in questione è questa...
Ora se tramite un'altra funzione richiamo la funzione showSetProtocol mi restituisce come valore sempre undefined.... anche se faccio ad esempio un alert(showSetProtocol(5,5)) mi restituisce sempre undefine... come mai? eppure se faccio un alert(str) all'interno della funzione stessa mi restituisce invece il valore numerico....come mai nel richiamarla mi perde il valore???? :master:Codice PHP:function showSetProtocol(idsocieta,iddocumento){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Attenzione: Questo browser non supporta AJAX!");
return;
}
var url="showSetProtocol.php?idsocieta="+idsocieta+"&iddocumento="+iddocumento;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
xmlHttp.onreadystatechange=function(){
if (xmlHttp.readyState==4)
{
if (xmlHttp.status==200)
{
var str = xmlHttp.responseText;
return str;
}else{
alert("Errore: "+xmlHttp.statusText+"\n\rResponse: "+xmlHttp.responseText);
return void(0);
}
}
}
}
per completezza, il codice che richiama la funzione è questa...
Codice PHP:case "protocollo":
if (typeof(valore) == 'undefined' || valore == "" || valore == 0){
var idsocieta = document.getElementById("societa").value;
var iddocumento = document.getElementById("documento").value;
var valore = showSetProtocol(idsocieta,iddocumento)+1;
alert (showSetProtocol(idsocieta,iddocumento));
if(isNaN(valore)){ valore = 1; }
}
document.getElementById("protocollo").value = valore;
input_str = '<input type="text" id="'+campo+'" name="'+campo+'" value="'+valore+'" size="35" onblur="javascript:controllaCaratteri(this,\'protocollo\');" />';
break;

Rispondi quotando