Ciao a tutti, ho il seguente problema: vorrei riuscire ad estrapolare i valori risultanti da una query sql come variabili di javascript e non come parti di html modificate dinamicamente... in poche parole:
chiaramente non funziona siccome entra nello stato 4 asincronicamente rispetto al normale flusso della funzione... ho quindi pensato ad utilizzare una variabie globae ma anche quello non funziona. una soluzione che ho trovato è stata la seguente; ma di qualità estremamente pessima, siccome dovrei riscrivere una funzione ajaxfunction per ogni utilizzo:codice:function ajaxFunction($querystring){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ ajaxRequest.responseText; //VORREI ESPORTARE QUESTA VARIABILE (response Text), QUI (*) } } ajaxRequest.open("GET", "ajax-example.php" + queryString, true); ajaxRequest.send(null); } function antani(){ var query="SELECT BLA BLA BLA..." var res=ajaxfunction(query); //* QUI VORREI AVERE LA VARIABILE }
quacuno mi sa aiutare?? grazie!codice:function antani(par1, par 2, par3, ..., risultato){ if(risultato==undefined){ var query="seect..."; ajaxfunction(par1, par2, par3,....,query) return 0; } else{ //evviva evviva ho il risultato sotto una variabile!!! } } function ajaxfunction(par1,par2,par3,...,query){ [...] ajaxRequest.onreadystatechange = function(par1,par3,par3,...){ if(ajaxRequest.readyState == 4){ antani(par1,par2,par3,....,ajaxRequest.responseText); } } [...] }

Rispondi quotando
