Ajax를 사용하여이를 수행 할 수 있습니다. 다음과 같이 사용하는 함수가 있습니다.
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;
}
첫 번째 매개 변수는 변경하려는 요소입니다. 두 번째 매개 변수는 변경할 요소에로드 할 파일 이름입니다. 세 번째 매개 변수는 사용중인 GET 또는 POST 데이터입니다 (예 : "total = 10000 & othernumber = 999"). 마지막 매개 변수는 POST를 사용하려면 true이고, GET하려면 false입니다.
이를 참조하십시오 : HTTP : //stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit –