Ciao ragazzi,
ho un problema con la funzione handleRequestStateChangePopolaTematiche.
Sto facendo delle prove con ajax e ho adattato una funzione già esistente. Quello che non capisco è perché quando viene richiamata questa funzione non vengono messe le parentesi solite () e perché se le metto (e magari modifico la funzione per passare un parametro) non funziona più nulla.
Qualcuno mi sa apiegare? Grazie
codice:// read a file from the server function popolaTematica(numeroelemento) { // only continue if xmlHttp isn't void if (xmlHttp) { // try to connect to the server try { var mainSelection = document.getElementById("id_tipologia_corso_"+ numeroelemento); // initiate reading a file from the server xmlHttp.open("POST", "tematica_corso.php", true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = handleRequestStateChangePopolaTematiche; xmlHttp.send("id_tipologia_corso=" + mainSelection.options[mainSelection.selectedIndex].value); } // display the error in case of failure catch (e) { alert("Can't connect to server:\n" + e.toString()); } } } // function called when the state of the HTTP request changes function handleRequestStateChangePopolaTematiche() { // when readyState is 4, we are ready to read the server response if (xmlHttp.readyState == 4) { // continue only if HTTP status is "OK" if (xmlHttp.status == 200) { try { // do something with the response from the server handleServerResponsePopolaTematiche(); } catch(e) { // display error message alert("Error reading the response: " + e.toString()); } } else { // display status message alert("There was a problem retrieving the data:\n" + xmlHttp.statusText); } } }

Rispondi quotando