Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created August 19, 2015 10:46
Show Gist options
  • Save deanhume/1655f7a0c5a93727e90a to your computer and use it in GitHub Desktop.
Save deanhume/1655f7a0c5a93727e90a to your computer and use it in GitHub Desktop.
A simple XHR request
function successListener() {
var data = JSON.parse(this.responseText);
console.log(data);
}
function failureListener(err) {
console.log('Request failed', err);
}
var request = new XMLHttpRequest();
request.onload = successListener;
request.onerror = failureListener;
request.open('get', './api/some.json', true);
request.send();
@alexsndf
Copy link

<div id="resultado"></div>

<script>
    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", "https://randomddduser.me/api/?results=3"); xhttp.onload = function() {
    document.getElementById("resultado").innerHTML = this.responseText; };
    xhttp.send();
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment