È possibile farlo utilizzando Ajax. Ho una funzione che uso per qualcosa del genere:
function ajax(elementID,filename,str,post)
{
var ajax;
if (window.XMLHttpRequest)
{
ajax=new XMLHttpRequest();//IE7+, Firefox, Chrome, Opera, Safari
}
else if (ActiveXObject("Microsoft.XMLHTTP"))
{
ajax=new ActiveXObject("Microsoft.XMLHTTP");//IE6/5
}
else if (ActiveXObject("Msxml2.XMLHTTP"))
{
ajax=new ActiveXObject("Msxml2.XMLHTTP");//other
}
else
{
alert("Error: Your browser does not support AJAX.");
return false;
}
ajax.onreadystatechange=function()
{
if (ajax.readyState==4&&ajax.status==200)
{
document.getElementById(elementID).innerHTML=ajax.responseText;
}
}
if (post==false)
{
ajax.open("GET",filename+str,true);
ajax.send(null);
}
else
{
ajax.open("POST",filename,true);
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajax.send(str);
}
return ajax;
}
Il primo parametro è l'elemento che si desidera modificare. Il secondo parametro è il nome del nome del file che stai caricando nell'elemento che stai modificando. Il terzo parametro sono i dati GET o POST che stai utilizzando, quindi ad esempio "total = 10000 & othernumber = 999". L'ultimo parametro è true se vuoi usare POST o false se vuoi GET.
fonte
2012-03-27 01:41:27
vedere questo: http: //stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit –