P/L/JavaScript

response state값 확인

야동우 2014. 1. 7. 16:19



<!DOCTYPE html>

<html>

<head>

<script>

function loadXMLDoc() {

var xmlhttp;

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

} else {// code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}


xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

alert('true');

}

}

xmlhttp.open("GET","http://www.naver.com",true);

xmlhttp.send();

}

</script>

</head>

<body>


<div id="myDiv"><h2>Let AJAX change this text</h2></div>

<button type="button" onclick="loadXMLDoc()">Change Content</button>


</body>

</html>






출처 : http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp