Code:
function PreparaDati(){
stringa = "";
var form = document.forms[0];
var numeroElementi = form.elements.length;
for(var i = 0; i < numeroElementi; i++){
if(i < numeroElementi-1){
stringa += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value)+"&";
}else{
stringa += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
}
}
}
function AJAXReq(method,url,bool){
if(window.XMLHttpRequest){
myReq = new XMLHttpRequest();
} else
if(window.ActiveXObject){
myReq = new ActiveXObject("Microsoft.XMLHTTP");
if(!myReq){
myReq = new ActiveXObject("Msxml2.XMLHTTP");
}
}
if(myReq){
execfunc(method,url,bool);
}else{
alert("Impossibilitati ad usare AJAX");
}
}
function execfunc(method,url,bool){
myReq.onreadystatechange = handleResponse;
myReq.open(method,url,bool);
myReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
myReq.send(stringa);
}
function InviaDati(){
PreparaDati();
AJAXReq("POST","getform.php",true);
}
il form è fatto così
Code:
<form method="post" action="getform.php" onsubmit="InviaDati(); return false;">
<label>Nick</label>: <input type="text" name="nick"><br />
<label>Email</label>: <input type="text" name="email"><br />
<label>Link</label>: <input type="text" name="link"><br />
<input type="submit" name="submit" value="Invia Dati" />
</form>
la risposta alla tua domanda è nelle funzioni AJAXReq() e execfunc()