“AJAX MDN” Kode Jawaban

AJAX MDN

<button id="ajaxButton" type="button">Make a request</button>

<script>
(function() {
  var httpRequest;
  document.getElementById("ajaxButton").addEventListener('click', makeRequest);

  function makeRequest() {
    httpRequest = new XMLHttpRequest();

    if (!httpRequest) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    httpRequest.onreadystatechange = alertContents;
    httpRequest.open('GET', 'test.html');
    httpRequest.send();
  }

  function alertContents() {
    if (httpRequest.readyState === XMLHttpRequest.DONE) {
      if (httpRequest.status === 200) {
        alert(httpRequest.responseText);
      } else {
        alert('There was a problem with the request.');
      }
    }
  }
})();
</script>
Lively Louse

AJAX MDN

adawdawdawgrg
Lively Louse

Jawaban yang mirip dengan “AJAX MDN”

Pertanyaan yang mirip dengan “AJAX MDN”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya