「AJAX」XMLHttpRequest.readyState プロパティのサンプル

説明
readyState
4 DONE 操作が完了した
status
200: “OK"
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<div id="cft">
<h2>XMLHttpRequestオブジェクト</h2>
<button type="button" onclick="loadFunc()">変更</button>
</div>
<script>
function loadFunc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("cft").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <div id="cft"> <h2>XMLHttpRequestオブジェクト</h2> <button type="button" onclick="loadFunc()">変更</button> </div> <script> function loadFunc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("cft").innerHTML = this.responseText; } }; xhttp.open("GET", "ajax_info.txt", true); xhttp.send(); } </script> </body> </html>
<!DOCTYPE html>
<html>
<body>

<div id="cft">
<h2>XMLHttpRequestオブジェクト</h2>
<button type="button" onclick="loadFunc()">変更</button>
</div>

<script>
function loadFunc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("cft").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
</script>

</body>
</html>

 

Ajax

Posted by arkgame