fetch api javascript
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});
fetch api javascript
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});
vanilla javascript api request
var xhr = new XMLHttpRequest();
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
const users = JSON.parse(xhr.response);
const content = document.getElementById("user_content");
for(let i in users){
let user_name = document.createElement("p");
let text = document.createTextNode(`User ID ${users[i].id}: ${users[i].title}`);
user_name.appendChild(text);
content.appendChild(user_name);
}
} else {
console.log('The request failed!');
}
console.log('This always runs...');
};
xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts');
xhr.send();
using apis in javascript
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest()
// Open a new connection, using the GET request on the URL endpoint
request.open('GET', url, true)
request.onload = function () {
// Begin accessing JSON data here
}
// Send request
request.send()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us