<script type="text/javascript">
var xmlHttp = getXmlHttpObject();
function insert_con_ajax(valore){
// attenzione a metere l'indirizzo giusto della pagina che elabora la richiesta
xmlHttp.open('GET', 'request.php?valore='+valore, true);
xmlHttp.onreadystatechange = function inserisci() {
if(xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
// stampa nel div con id messaggio tutto ciò che va in output nella pagina reques.php
document.getElementById("messaggio").innerHTML=xmlHttp.responseText;
}
}
};
xmlHttp.send(null);
}
function prendiValore(campo) {
return document.getElementById(campo).value;
}
function getXmlHttpObject() {
var xmlHttp=null;
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
xmlHttp = new XMLHttpRequest();
}
if (window.ActiveXObject) {
// IE5, IE6
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
</script>
<input type="text" id="valore" name="valore"/>
<input type="button" value="Inserisci" onclick="insert_con_ajax(prendiValore('valore'));"/>
<!-- qui verrà mostrato il messaggio -->
<div id="messaggio"></div>