JS/Ajax 2009. 7. 24. 16:36

다음은 AJAX로 파일 내용을 가져오는 예제이다.

<script type="text/javascript">
var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}

http.open("GET", "test.txt");
http.onreadystatechange=function() {
  if(http.readyState == 4) {
    document.write(http.responseText);
  }
}
http.send(null);
</script>

text.txt 대신 URL을 넣으면 해당 URL의 내용을 가져온다.

Reference:
http://daniel.lorch.cc/docs/ajax_simple/

posted by 나는너의힘
: