12345

AJAX를 사용할때는 XMLHttpRequest 객체를 만들어서 사용해야 하는데, 페이지마다 항상 반복적인
코드가 필요하기 떄문에 자바스크립트 파일로 따로 분리해주도록 한다~


 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','appliaction/x-www-form-urlencoded');
     httpRequest.onreadystatechange = callback;
     httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}

TRACKBACK ADDRESS : http://josuae.tistory.com/trackback/174 관련글 쓰기
이름 :
비밀번호 :
홈사이트 :
비밀글 :
*1  *2  *3  *4  *5  *6  ... *147 
ㅠㅠ
알립니다
episode
activity
blog
everyday
programming
portfolio
seminar
thinking
nonclassified
secret scrap
ipod touch
count total 68,931, today 4, yesterday 11