/*------------------------------------------------------------------------------ * 1. ÆÄÀϸí: ajax.js * 2. ¼³ ¸í: AJAX¸¦ ÀÌ¿ëÇÑ Ã³¸®¿Í °ü·ÃµÈ ÇÔ¼ö¸¦ Á¤ÀÇÇÑ´Ù. * 3. ÀÇÁ¸¼º: * 4. ÀÛ¼ºÀÚ: * 5. ÀÛ¼ºÀÏ: 2006.12.15. -----------------------------------------------------------------------------*/ /** * XMLHttpRequest¸¦ ÅëÇØ 󸮸¦ ¿äûÇÑ´Ù. * 󸮴 sync. ÇÏ°Ô ÀϾµµ·Ï ÇÑ´Ù. */ function send(url) { var res = null; /* XMLHttpRequest¸¦ ¾ò´Â´Ù. */ var xmlHttp = getXMLHttpRequest(); if ( xmlHttp != null ) { xmlHttp.open("GET", url, false); // µ¿±â·Î È£Ãâ. xmlHttp.send(null); res = eval("(" + xmlHttp.responseText + ")"); } /* »ç¿ëÇÑ XMLHttpRequest¸¦ µ¹·ÁÁØ´Ù. */ returnXMLHttpRequest(xmlHttp); return res; } /** * XMLHttpRequest¸¦ ÀÌ¿ëÇÏ¿© POST ¹æ½ÄÀ¸·Î 󸮸¦ ¿äûÇÑ´Ù. * 󸮴 sync. ÇÏ°Ô ÀϾ´Ù. */ function sendForm(form) { var res = null; var url = form.action; var xmlHttp = getXMLHttpRequest(); if ( xmlHttp != null ) { xmlHttp.open("POST", url, false); // µ¿±â·Î È£Ãâ. /* POST·Î Á¤º¸¸¦ º¸³»±â Àü¿¡ Content-Type °ªÀ» ¼³Á¤ÇÑ´Ù. */ var contentType = "application/x-www-form-urlencoded; charset=UTF-8"; xmlHttp.setRequestHeader("Content-Type", contentType); /* POST·Î º¸³¾ µ¥ÀÌŸ¸¦ »ý¼ºÇÑ´Ù. */ var postData = makePostData(form); xmlHttp.send(postData); res = eval("(" + xmlHttp.responseText + ")"); } /* »ç¿ëÇÑ XMLHttpRequest¸¦ µ¹·ÁÁØ´Ù. */ returnXMLHttpRequest(xmlHttp); return res; } /** * ÁÖ¾îÁø Form¿¡ ÀÖ´Â Á¤º¸¸¦ POST ·Î ½Ç¾î º¸³¾ * ÀÚ·á Çü½ÄÀ¸·Î ¸¸µé¾î µ¹·Á ÁØ´Ù. */ function makePostData(form) { var data = ""; var length = form.elements.length; for ( var i = 0; i < length; i++ ) { if ( i > 0 ) data += "&"; var elem = form.elements[i]; /* Disabled µÈ Ç׸ñÀº º¸³»Áö ¾Ê´Â´Ù. */ if ( elem.disabled ) continue; /* ÀÚ·áÇüŰ¡ radio³ª checkboxÀÎ °æ¿ì´Â checkµÈ Ç׸ñÀÇ °ª¸¸ º¸³½´Ù. value Ç׸ñÀÌ Á¤ÀǵǾî ÀÖÁö ¾ÊÀ¸¸é true¸¦ º¸³½´Ù. */ if ( ( elem.type == "radio" || elem.type == "checkbox" ) && elem.checked ) { data += elem.name + "=" + ( isEmpty(elem.value) ? "true" : encodeURIComponent(elem.value) ); } else { /* typeÀÌ text³ª select-single ÀÎ °æ¿ì. select-multi ÀÎ °æ¿ì´Â ÀÏ´Ü °í·Á ¾È ÇÑ´Ù. */ data += elem.name + "=" + encodeURIComponent(elem.value); } } return data; } /** * XMLHttpRequest °´Ã¼¸¦ µ¹·Á ÁØ´Ù. * ÀÌ¹Ì »ý¼ºµÇ¾î »ç¿ëÁßÀÌÁö ¾ÊÀº °Ô ÀÖÀ¸¸é À̸¦ ÁÖ°í * »ç¿ëÁßÀÌ ¾Æ´Ñ °Ô ¾øÀ¸¸é ¸¸µé¾î µ¹·Á ÁØ´Ù. */ var httpReqStack = new Array(); function getXMLHttpRequest() { var httpReq = null; if ( httpReqStack.length > 0 ) { httpReq = httpReqStack.pop(); } else { httpReq = newXMLHttpRequest(); } return httpReq; } /** * ÀÌ¹Ì »ç¿ëÇÑ XMLHttpRequest¸¦ µ¹·Á¹Þ´Â´Ù. */ function returnXMLHttpRequest(httpReq) { httpReqStack.push(httpReq); } /** * ºê¶ó¿ìÀúÀÇ Á¾·ù¿¡ ¸Â°Ô XMLHttpRequest °´Ã¼¸¦ »ý¼ºÇÏ¿© * µ¹·Á ÁØ´Ù. */ function newXMLHttpRequest() { var reqHttp; if ( window.ActiveXObject ) { // IE try { reqHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { reqHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e1) { reqHttp = null; } } } else if ( window.XMLHttpRequest ) { // IE ÀÌ¿Ü try { reqHttp = new XMLHttpRequest(); } catch (e) { } } if ( reqHttp == null ) { alert("XMLHttpRequest °´Ã¼¸¦ »ý¼ºÇϴµ¥ ½ÇÆÐÇÏ¿´½À´Ï´Ù."); } return reqHttp; } function deleteAllRow(obj) { var childCount = obj.childNodes.length; for ( var i = (childCount - 1); i >= 0; i-- ) { obj.deleteRow(i); } } function makeTableRow(dataArray) { var rowObj = document.createElement("tr"); for ( var i = 0; i < dataArray.length; i++ ) { var dataObj = document.createElement("td"); dataObj.innerHTML = dataArray[i]; rowObj.appendChild(dataObj); } return rowObj; }