1var xhttp = new XMLHttpRequest();
2xhttp.onreadystatechange = function() {
3 if (this.readyState == 4 && this.status == 200) {
4 // Typical action to be performed when the document is ready:
5 document.getElementById("demo").innerHTML = xhttp.responseText;
6 }
7};
8xhttp.open("GET", "filename", true);
9xhttp.send();
1function reqListener () {
2 console.log(this.responseText);
3}
4
5var oReq = new XMLHttpRequest();
6oReq.onload = reqListener;
7oReq.open("GET", "http://www.example.org/example.txt");
8oReq.send();
1function httpGetAsync(url, callback) {
2 var xmlHttp = new XMLHttpRequest();
3 xmlHttp.onreadystatechange = function() {
4 if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
5 callback(xmlHttp.responseText);
6 }
7 xmlHttp.open("GET", url, true); // true for asynchronous
8 xmlHttp.send(null);
9}