1fetch('https://jsonplaceholder.typicode.com/todos/1')
2 .then(response => response.json())
3 .then(json => console.log(json))
1var xhr = new XMLHttpRequest();
2xhr.open("GET", "https://reqres.in/api/products/3", true);
3xhr.onload = function(){
4 console.log(xhr.responseText);
5};
6xhr.send();
7
1fetch('https://jsonplaceholder.typicode.com/todos/1')
2 .then(response => response.json())
3 .then(json => console.log(json))
4
1// fetch format
2fetch('https://jsonplaceholder.typicode.com/posts', {
3 method: 'POST',
4 body: JSON.stringify({
5 title: 'foo',
6 body: 'bar',
7 userId: 1,
8 }),
9 headers: {
10 'Content-type': 'application/json; charset=UTF-8',
11 },
12})
13 .then((response) => response.json())
14 .then((json) => console.log(json));
1 axios
2 .get("https://jsonplaceholder.typicode.com/posts")
3 .then(function (response) {
4 console.log(response);
5 })
6 .catch(function (error) {
7 // handle error
8 console.log(error);
9 })
10 .then(function () {
11 // always executed
12 });
1fetch('https://jsonplaceholder.typicode.com/todos/1')
2 .then(response => response.json())
3 .then(json => console.log(json))
4fetch('https://jsonplaceholder.typicode.com/todos/1')
5 .then(response => response.json())
6 .then(json => console.log(json))