AJAX Core Module .js Example

AJAX Core Module.js

commXMLHttp.js <-- 이 부분이 핵심
welcome.txt
receiveTextFile.htm
filereceive.js


----welcome.txt---------------
안녕하세요 Hello World !
----end of document ----------

----receiveTextfile.htm-------

<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr"/>
<script language="javascript" type="text/javascript" src="commXMLHttp.js"></script>
<script language="javascript" type="text/javascript" src="filereceive.js"></script>
</head>
<body>
<h1>Receive the Server of Textfile</h1>


<div id="btnarea">
 <input type="button" id="btnClick" name="btnClick" value="ReceiveTheServerFile" onclick="initialValueSet()"/>
</div>
<div id="datashow">
 <div id="receiveData"></div>
</div>
</body>
</html>

----end of document-------------------

===== filereceive.js =====================================================
// JScript source code
function initialValueSet() {
var getorpost = "GET";
var urlfileapp = "welcome.txt";
var trueoffalse = true;
var senddata = "";
AjaxCore_openSendStatus_CJIJ(getorpost, urlfileapp, trueoffalse, senddata, AjaxCore_mainControl_CJIJ);
}

function AjaxCore_mainControl_CJIJ(xmlHttp){
alert(xmlHttp.reponseText);
document.getElementById("receiveData").innerHTML = xmlHttp.reponseText;
}
===== end of document ===========================================



################## AJAX Core Module ###################################3
// CREATE the XMLHttpRequest ActiveX Object
function AjaxCore_createXMLHttpRequest_CJIJ(){

var reqHttp;
if (window.ActiveXObject) {
try{
reqHttp = new ActiveXObject("Msxml2.XMLHTTP"); //after IE 5.0 browser
}catch(e1){
try{
reqHttp = new ActiveXObejct("Microsoft.XMLHTTP");
}catch(e){
reqHttp = null;
}
}
} else if (window.XMLHttpRequest){
try{
reqHttp = new XMLHttpRequest();
}catch(e2){
reqHttp = null;
}
}

if (reqHttp == null) errorMessage(); //unable XMLHTTPRequest..

return reqHttp;
}

// Check the readyState and status
function AjaxCore_openSendStatus_CJIJ(getorpost, urlfileapp, trueoffalse, senddata, callbackFunction){

var xmlHttp = AjaxCore_createXMLHttpRequest_CJIJ(); // CREATE XMLHttpRequest
xmlHttp.open(getorpost, urlfileapp, trueoffalse); //1:transfer method, 2:url, 3:Asynchronous or synchronous
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4){ //server status
if(xmlHttp.status == 200){ //response status
if(callbackFunction != null){
callbackFunction(xmlHttp);
}
}else{
AjaxCore_exceptionControl_CJIJ(xmlHttp);
}
}
}

var conType = "application/x-www-form-urlencoded;";
xmlHttp.setRequestHeader("Content-Type", conType);
xmlHttp.send(senddata);
}

function AjaxCore_errorHandler_CJIJ(){
//do something.. alert("unable Browser, change to IE or FireFox or Opera..and so on");
}

function AjaxCore_exceptionControl_CJIJ(xmlHttp){
switch(xmlHttp.status){
case 500:
alert("Interal Server Error");
break
case 404:
alert("URL or file Missing");
break;
case 403:
alert("Access deny");
break;
default:
alert(xmlHttp.status +"\n"+ xmlHttp.statusText + " : It's The fail between sever to client browser response transfer");
}

//do something.. example. It's The fail between sever to client browser response transfer
}

function AjaxCore_commAddListener(paramObject, paramType, paramFunction, paramFalse){
if(paramObject.attachEvent){
paramObject.attachEvent("on"+paramType, paramFunction);
}else{
paramObject.addEventListener(paramType. paramFunction, paramFlase);
}
}
############### End of Document ######################################