jQuery

jQuery In Action chapter 8-1

우혁이 아빠 2009. 12. 20. 13:52

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>예제 8.3</title>
 <script type="text/javascript">
 window.onload = function (){
  var xhr;

  if (window.XMLHttpRequest) {
   xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) { 
   xhr = new ActiveXObject("Msxml2.XMLHTTP");
  } else {
   throw new Error("Ajax를 지원하지 않는 브라우저입니다.");
  }

  xhr.onreadystatechange = function (){
   if (xhr.readyState == 4) {
    if (xhr.status >= 200 && xhr.status < 300) {
     document.getElementById('someContainer').innerHTML = xhr.responseText;
    }
   }
  };
  xhr.open('GET', 'someResource');
  xhr.send('');
 };
 </script>
</head>
<body>
 <div id="someContainer"></div>
</body>
</html>