//Using the javascript Fetch API
//References: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
fetch('http://localhost:8080/test')
.then((response) => response.json())
.then((data) => console.log(data));
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
httpGetAsync("/api/v1/items", (res)=>{
// page content is in variable "res"
});
const requests = new XMLHTTPRequest();
requests.open('METHOD', url)
requests.send()
requests.onload = () => {
if (requests.status == 200) {
console.log('ok')
} else {
console.log('didnt work')
}
}
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send(null);
}
const xhr = new XMLHttpRequest();
JavaScriptCopy
xhr.open(Method, URL[, Async]);
JavaScriptCopy