Salve a tutti!
Ho un banalissimo script AJAX che invia il testo preso da un campo di un form ad un file php.
Vi spiego il codice e poi il problema.
ora il codice presente in texto.php (la pagina lato server che dovrebbe elaborare i dati:codice://codice javascript var xmlHttp = getXmlHttpObject(); var waiting = false; function getXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } //di seguito la funzione che... non funziona! function scritto(campoText) { if(xmlHttp && !waiting) { var data1= campoText; xmlHttp.open("POST", 'texto.php', true); xmlHttp.onreadystatechange = stateChanged; xmlHttp.send(data1); alert(data1); waiting = true; } } //e quindi la funzione stateChanged: function stateChanged() { if(xmlHttp.readyState == 4) { //Stato 200 = OK if (xmlHttp.status == 200) { var resp = xmlHttp.responseText; alert(resp); } waiting = false; } }
e quindi, per ultimo, il codice html del form:codice:<?php if(!isset($_POST['campoText'])){ $r = "Non valido"; } else { $campoText = $_POST['campoText']; $r = $campoText; } echo $r; ?>
Come potete vedere, lo script non fa altro che passare il parametro campoText alla pagina lato server, che dovrebbe rispondere con il testo inserito nella textBox. Invece, l'errore che ricevo è sempre "Non valido", come se non venisse mai verificata la isset di PHP.codice:<form name="firmasz" method="POST" action=<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?> > <input type="text" id="campoText" onblur="scritto(this.value)" /> </form>
A me sembra tutto corretto... ma siccome sto muovendo i primi passi con AJAX... quale potrebbe essere il problema?
Grazie a tutti!

Rispondi quotando