프로그램/script

Base AJax Function Example

mulderu 2012. 3. 4. 19:38
-- 아래는  tworld  에서 카피한 함수들입니다. 
-- jQuery  같은 라이브러리를 이용하지 않는 경우 유용할 수 있습니다.

var xmlHttp;
var userFunction;

function createXMLDocRequest(fXml) {
var xmlDoc;
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
} else if (window.XMLHttpRequest) {
xmlDoc = document.implementation.createDocument('', '', null);
}
xmlDoc.async = false;
xmlDoc.load(fXml);
return xmlDoc;
}
function createXMLTextRequest(fXml) {
var xmlDoc;
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.loadXML(fXml);
} else if (window.XMLHttpRequest) {
xmlDoc = document.implementation.createDocument('', '', null);
var parser = new DOMParser();
xmlDoc = parser.parseFromString(fXml, 'text/xml');
delete parser;
}
return xmlDoc;
}
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function doRequestUsingGET(vStr, uFun) {
userFunction = uFun;
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open('GET', vStr, false);
xmlHttp.send(null);
}
function doRequestUsingPOST(vUrl, vStr, uFun) {
userFunction = uFun;
createXMLHttpRequest();
xmlHttp.open('POST', vUrl, false); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp.send(vStr); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { try { eval(userFunction); } catch(e) {} } else if (xmlHttp.status == 404) { alert('잘 못된 페이지를 호출하였습니다.'); } } } function hangleCheck(value) { return escape(value).replace(/\+/g, '%2B'); } function tworldLogo() { //document.write("<embed id='TworldLogo' src='http://www.tworld.co.kr/inc/sound/TRING.wav' loop='false' autostart='false' hidden='true'></embed>"); }