<form method="post" action="test.do" onsubmit="sendRequest();return false">
function getRequestBody(oForm){
var aParams=new Array();
for(var i=0;i<oForm.elements.length;i++){
var sParam=encodeURIComponent(oForm.elements[i].name);
sParam+="=";
sParam+=encodeURIComponent(oForm.elements[i].value);
sParams.push(sParam);
}
return aParams.join("&");
}
function sendRequest(){
var oForm=document.forms[0];
var sBody=getRequestBody(oForm);
var oXmlHttp=createRequest();
oXmlHttp.open("post",oForm.action,true);
oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
oXmlHttp.onreadystatechange=function(){
if(oXmlHttp.readyState==4){
saveResult(oXmlHttp.responseText);
}else{
saveResult("An error accurred: "+oXmlHttp.statusText);
}
}
oXmlHttp.send(sBody);
}
posted on 2006-10-08 15:48
周锐 阅读(612)
评论(0) 编辑 收藏 所属分类:
Ajax