vendredi 22 avril 2016

Trying to take server response

I'm trying to creat a simple web app that shows the server response in a page but I'm pretty newbie.

When acessing this page http://ift.tt/26kGQHa, it generates a response. How do I can capture it and put it in my HTML page?

Please tell me the simplest way. :D

I'm executing a simple code with XMLHttpRequest(). Exactly as shown:

<!DOCTYPE html>
<html>
<body>

<script>
function test() {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', 'http://ift.tt/26kGQHa', true);
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
      alert(xhr.responseText);
      alert("GOOD");
    }
    else alert("BAD");
  };alert("EXIT");
};
</script>
<button onclick='test()'>Click</button>
</body>
</html>

I've wrote the alerts just to test the code. But it never shows the "GOOD" and "BAD" for me.




Aucun commentaire:

Enregistrer un commentaire