상세 컨텐츠

본문 제목

ajax 기초

인터넷/프로그래밍/홈페이지

by 길상여의 2008. 10. 27. 20:34

본문

// XMLHttpRequest 오브젝트 생성
// 사용예) obj = createHttpRequest();
//
function newXMLHttpRequest(){
  var xmlHttp;

  if (window.ActiveXObject) { // IE일 때
    // IE
    try{
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try{
        xmlHttp = new ActiveObject("Microsoft.XMLHTTP")
      } catch(e2) {
        xmlHttp = null;
      }
    }
  } else if (window.XMLHttpRequest) {
    // IE 외
    try{
      xmlHttp = new XMLHttpRequest();
    } catch(e) {
      xmlHttp = null;
    }
  }
 
  if (xmlHttp == null) { errorMessage(); }

  return xmlHttp;
}

function errorMessage(){
  alert("지원 안되는 브라우저");
}


관련글 더보기