Buongiorno. Eccomi con un altro problema..
Come posso inviare una variabile da javascript a php?
ho provato con Ajax in questo modo ma non va..
In pratica voglio che quando il form viene inviato, il client crea un'altra variabile (che non viene inserita dall'utente) e la invia al server:
file index.html
file gestori.jsCodice:<input type="submit" value="INVIA" onsubmit="ajaxGestore();">
file data.phpCodice:function ajaxGestore() { var xmlHttp; try { xmlHttp = new XMLHttpRequest(); } catch (e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { window.alert("Il tuo browser non supporta AJAX!"); return false; } } } xmlHttp.open('GET', "./data.php?citta=Pisa", true); xmlHttp.send(null); }
L'errore che mi esce è questo:Codice:<?php echo $_GET['citta'] ?>
Notice: Undefined index: citta
poi ho provato a creare un form dinamicamente ma esce lo stesso errore:
non so più cosa provare..Codice:var gestore() { var form = document.createElement("form"); form.setAttribute("action", "./data.php"); form.setAttribute("method", "post"); input = document.createElement("input"); input.setAttribute("type", "button"); input.setAttribute("name", "citta"); input.setAttribute("value", "pisa"); form.appendChild(input); document.body.appendChild(form); form.submit(); document.body.removeChild(form); }
grazie!!

LinkBack URL
About LinkBacks


