Guest User

XMLHttpRequest

a guest
Jul 9th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function httpGet(url){
  2.     var string;
  3.     var xhr = new XMLHttpRequest();
  4.     xhr.open("GET", url, true);
  5.     xhr.onreadystatechange = function(){
  6.         if (xhr.readyState == 4 && xhr.status == 200) {
  7.             //console.log(xhr.responseText);
  8.             string = xhr.responseText;
  9.             console.log("string1: " + string);
  10.         }
  11.     }
  12.     xhr.send();
  13.     console.log("string2: " + string);
  14.     return (string);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment