ajax_basic.js
//XMLHttpRequest ๊ฐ์ฒด ๋ณ์ ์ ์ธ
var req = null;
//XMLHttpRequest ๊ฐ์ฒด ์์ฑ
function getXMLHttpRequest(){
//๊ฐ์ฒด ํ์ง ๊ธฐ๋ฒ์ผ๋ก XHR ๊ฐ์ฒด ๋ฆฌํด
if(window.XMLHttpRequest){ //mozilla ff,safari,opera
return new XMLHttpRequest();
}else if(window.ActiveXObject){ //ie
try{
return new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
return new ActiveXObject(
"Microsoft.XMLHTTP");
}catch(e){ return null; }
}
}
return null;
}
//์๋ฒ์ ์ ์ก์ ๋ด๋นํ๋ ํจ์
/*
* method : ์ ์ก๋ฐฉ์(get,post)
* url : ์๋ฒ ์ฃผ์
* data : ์ ๋ฌํ ํ๋ผ๋ฏธํฐ
* handler : ์๋ต์ ๋ฐ์ํ ํจ์
*/
function sendRequest(method, url, data, handler){
//์ ์ก๋ฐฉ์ ๊ฒ์ฌ
if(method == null || method == ''){
//๊ธฐ๋ณธ์ผ๋ก get๋ฐฉ์์ ์ง์ ํ๋ค
method = "get";
}
//๋ชจ๋ ์ฃผ์๊ฐ ๋๊ฐ์ด ์ธ์๋์ง ์๊ฒ ํ๋ ๊ธฐ๋ฒ
url = url + ";now=" + new Date();
//๋ง์ฝ ์ ์ก๋ฐฉ์์ด get์ด๋ฉด url ๋ค์ data๋ฅผ ๋ถ์ฌ์ผ ํ๋ค.
if(method == 'get'){
url = url + "?" + data;
//๊ทธ๋ฌ๊ณ ๋ post๋ฐฉ์ ์ ์ก์ ๋๋นํด null๋ก ๋ณ๊ฒฝ
data = null;
}
//์ด์ ์ฌ์ฌ ์ ์กํด ๋ณด์
req = getXMLHttpRequest();
req.open(method, url, true);
req.onreadystatechange = handler;
req.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded");
req.send(data);
}
//๋ฌธ์์์ id์ ํด๋นํ๋ ์์์ ๊ฐ์ ๋ฆฌํดํ๋ ํจ์
function getValue(obj) {
var ele = document.getElementById(obj);
if(ele == null) {
return = "no data";
}
return ele.Value;
}