Created
February 19, 2019 00:47
-
-
Save srkiNZ84/b1d57a7ff9a61408f3125ce5715b7304 to your computer and use it in GitHub Desktop.
Simple example of how to use XHR to call and enpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Testing XHR</title> | |
</head> | |
<body> | |
<p>This is a test</p> | |
<br /> | |
<div id="foobar"></div> | |
<script> | |
// Create the HTTP request | |
var xhr = new XMLHttpRequest(); | |
xhr.onload = function() { | |
if( xhr.status >= 200 && xhr.status < 300){ | |
console.log('success!', xhr); | |
document.getElementById('foobar').innerHTML = xhr.responseText; | |
//document.getElementById('foobar').innerHTML = xhr.response; | |
} | |
else { | |
console.log('The request failed!'); | |
} | |
console.log('End of function'); | |
}; | |
//xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts'); | |
xhr.open('GET', 'https://us-central1-faas-helloworld.cloudfunctions.net/pyhttp'); | |
//xhr.responseType = 'json'; | |
xhr.send(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment