'Ajax'에 해당되는 글 3건

jQuery Ajax

Ajax 2011. 6. 23. 15:43

// jquery ajax
 //body onload 과 같은 효과 굳이 html 에 안써줘도 자동 콜백
 $(document).ready(function(){
  var yes = "y";
  var param = "babo=" + yes;
  $.ajax({
   type:"GET",
   url:SERVICE_URL+"/study/ajax.jsp",
   data:param,
   success:function(msg){
   ajax_data_area.innerHTML = msg;
   }
  });
 });
//=======끝 jquery 개 깔끔
// jQuery js 파일 있어야 함

'Ajax' 카테고리의 다른 글

보통 Ajax  (0) 2011.06.23
Ajax httpRequest.js  (0) 2011.06.23
블로그 이미지

스마트전

,

보통 Ajax

Ajax 2011. 6. 23. 15:41

//----------------------------------------------
// 보통 ajax  body="onload" 로 초기 실행
 function onStartDom(){
  // httpRequest.js  SERVICE_URL <--url 상수 
  var yes = "y";
  var param = "babo=" + yes;  //파라미터는 이런식으로 2개 이상일때 "&param="  1개일때 ?제외
  sendRequest(SERVICE_URL+"/study/ajax.jsp", param, a_callBack, "GET");
  }
 
 //ajax 콜백 메소드
 function a_callBack(){
  // 알지? 200 코드일때 들어오기
  if(httpRequest.readyState == 4){
   if(httpRequest.status == 200){
    var htmlDoc = httpRequest.responseText;
    // div id ajax_data_area 에 데이터 넣기
    ajax_data_area.innerHTML = htmlDoc;
   } else {
    
   }
  }
 }
//------------------------------------------------------

'Ajax' 카테고리의 다른 글

jQuery Ajax  (0) 2011.06.23
Ajax httpRequest.js  (0) 2011.06.23
블로그 이미지

스마트전

,

Ajax httpRequest.js

Ajax 2011. 6. 23. 15:39


var SERVICE_URL = '상수 url';

function getXMLHttpRequest(){
 if(window.ActiveXObject){
  try{
   return new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
   try{
    return new ActiveXObject("Microsoft.XMLHTTP");
   }catch(e1){
    return null;
   }
  }
 }else if(window.XMLHttpRequest){
  return new XMLHttpRequest();
 }else{
  return null;
 }
}
var httpRequest = null;

function sendRequest(url, params, callback, method){
 httpRequest = getXMLHttpRequest();
 var httpMethod = method ? method : 'GET';
 if(httpMethod != 'GET' && httpMethod != 'POST'){
  httpMethod = 'GET';
 }
 var httpParams = (params == null || params == '') ? null : params;
 var httpUrl = url;
 if(httpMethod == 'GET' && httpParams != null){  
  httpUrl = httpUrl + "?" + httpParams;
 }
 httpRequest.open(httpMethod, httpUrl, true);
 httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 httpRequest.onreadystatechange = callback;
 httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}

'Ajax' 카테고리의 다른 글

jQuery Ajax  (0) 2011.06.23
보통 Ajax  (0) 2011.06.23
블로그 이미지

스마트전

,