Getting data from a website using XMLHttpRequest - Javascript Language Basics

Javascript examples for Language Basics:XMLHttpRequest

Description

Getting data from a website using XMLHttpRequest

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript">
function go(){/*from w  ww . j  av a  2 s .  c  o m*/
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://your server dot com", false);
xhr.onreadystatechange = function(){
  if (xhr.readyState == 4)
  {
    document.write(xhr.responseText);
  }
  else
  {
    document.write("nope");
  }
}
xhr.send();}

      </script> 
   </head> 
   <body onload="go()">  
   </body>
</html>

Related Tutorials