//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);
}
document.addEventListener("DOMContentLoaded", function() {
const xmlHttp = new XMLHttpRequest(),
div = document.getElementById('music_all_ajax');
xmlHttp.open("GET", '{{ route('music ') }}', false); // false for synchronous request
xmlHttp.send(null);
div.insertAdjacentHTML('afterbegin', xmlHttp.responseText);
});
const xhr = new XMLHttpRequest();
JavaScriptCopy
xhr.open(Method, URL[, Async]);
JavaScriptCopy