ajax 의 두 가지 상용 호출 방식

방식 1:
//  js
<script language="javascript">
var _object;
var xmlhttp = null;
var interval = null;
var rtnData = new Array();
var btype;

//       
//ie firefox ajax             
function getOs(){ 
 var OsObject = ""; 
 if(navigator.userAgent.indexOf("MSIE")>0) {
  return "MSIE"; //IE   
 } 
 if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
  return "Firefox"; //Firefox   
 } 
 if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
  return "Safari"; //Safan   
 } 
 if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
  return "Camino"; //Camino   
 } 
 if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
  return "Gecko"; //Gecko   
 }
}


function loadXMLDoc(xmlName,dataTypeId){
 //        
 var ivkUrl = "<%=path%>/jsp/DataRequest/autoFindRtnDataGTS.jsp?xmlName=" + xmlName + "&"+ Math.random();
 //alert("** ivkUrl = "+ ivkUrl);
   
 if (window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
 }else if (window.ActiveXObject){
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
   
 if (xmlhttp){
  xmlhttp.open("GET",ivkUrl,false);
      
     btype = getOs();
     if(btype != "Firefox"){//IE  state_Change  
      xmlhttp.onreadystatechange = state_Change;
  }      
  xmlhttp.send(null);
      
  if(btype == "Firefox"){//Firefox     
   var dataTypeId = "<%=dataTypeId%>";      
   if(dataTypeId == 1){
    updatePage();//    
   }
  }
 }else{
  alert("Your browser does not support XMLHTTP");
 }
 
 //  10   1 
 interval = window.setTimeout("loadXMLDoc('<%=xmlName%>','<%=dataTypeId%>')", 10000);
 if(rtnData.length == 1 && rtnData[0].downUrl){//1     
  window.clearTimeout(interval);
 }
 if(rtnData.length > 1){//      
  window.clearTimeout(interval);
 }
}


function state_Change(){
 var dataTypeId = "<%=dataTypeId%>";
 
 if (xmlhttp.readyState==4){
  if (xmlhttp.status==200){
   if(dataTypeId == 1){
    updatePage();//    
   }
  }
 }
}

//js         
rtnData = eval(xmlhttp.responseText);

 
 
방식 2:
 
if (xmlhttp){
 try{
  xmlhttp.open("POST",'DateValidator.do',false);
     xmlhttp.send(currStartDate+"##"+currEndDate);//    
 }catch (exception){
  alert(exception);
 }
 
 //js         
 rtnData = xmlhttp.responseText;
 ....      
}else{
 alert("Your browser does not support XMLHTTP");
}

 
 
자바 엔 드 처리:
String dateString = (String)requestObj.getData("REQUEST_XMLHTTP");//  ajax     
String[] dateArray = dateString.split("##");

좋은 웹페이지 즐겨찾기