Coggle requires JavaScript to display documents.
posts = loadPostsSync();
loadPostsAsync(function () { ... });
fetch("test.txt").then(function (response) { ... })
.then(function (data) { ... })
.catch(function (err) { ... )
return response.text();
fetch("posts.json").then(function (response) { ... })
return response.json();
.then(function (data) { ... }
.catch(function (err) { ... }
.then(function (response) { ... }
fetch("test.txt")
async get(url) { ... }
const response = await fetch(url);
const resData = await response.json();
return resData;
async post(url, data) { ... }
const response = await fetch(url, { ... }
async put(url, data) { ... }
async delete(url) { ... }
const resData = await "deleted";
return new Promise(function (resolve, reject) { ... }
return new Promise(function(resolve, reject){ ... }
setTimeout(function () { ... resolve(); ... reject(); }, 1000);
function createPost(post) { return new Promise(function (resolve, reject) { setTimeout(function () { posts.push(post); const error = true; if (!error) { resolve(); } else { reject("fag"); } }, 3000); }); }
createPost({ title: "post2", body: "this is body2" }).then(getPosts);
createPost({ title: "post2", body: "this is body2" }).then(getPosts).catch(function(err) { ... });
xhr.open('GET, 'data.txt, true);
xhr.onLoad = function() { ... }
this.status
xhr.send()
xhr.onreadystatechange = function() { ... }
xhr.onprogress = function(){ ... }
xhr.onerror = function() { ... };
xhr.status
xhr.responseText
xhr.readyState
const xhr = new XMLHttpRequest();
{ "id": 1, "name": "John Doe", "company": "123 Designs", "phone": "444-555-6666" }
[{ ... }, { ... }, { ... }];
xhr.open('GET', 'customer.json', true);
xhr.send();
xhr.onload = function(){ ... }
const customer = JSON.parse(this.responseText);
customers.forEach(function (customer) { output += ... }
xhr.open('GET', http://api.icndb.com/jokes/random/${number}, true);
const response = JSON.parse(this.responseText);
output += <li>${joke.joke}</li>;
document.querySelector('.jokes').innerHTML = output;
response.value.forEach(function(joke){ ... }
document.querySelector('.get-jokes').addEventListener('click', getJokes);
{ "type": "success", "value": { "id": , "joke": } }
const sayHello = function () { ... }
const sayHello = () => { ... }
const sayHello = () => console.log("hello");
const sayHello = () => "hello";
const sayHello = () => ({msg: 'hello'});
const sayHello = (justAnotherName) => console.log(justAnotherName});
const sayHello = justAnotherName => console.log(justAnotherName});
nameLengths = users.map((userName) => { ... })
nameLengths = users.map((userName) => userName.length);
function getText() { ... }
.then((response) => response.text())
.then((data) => console.log(data))
.catch((err) => console.log(err));
http.get("https://jsonplaceholder.typicode.com/users")
const http = new EasyHTTP();
http.post("https://jsonplaceholder.typicode.com/users", data)
http.put("https://jsonplaceholder.typicode.com/users", data)
http.delete("https://jsonplaceholder.typicode.com/users/2")
class EasyHTTP { ... }
get(url) { ... }
return new Promise((resolve, reject) => { ... });
fetch(url)
.then((response) => response.json())
.then((data) => resolve(data))
.catch((err) => reject(err));
post(url) { ... }
fetch(url, { ... })
{ method: 'POST', headers: {'Content-type':'application/json'}, body: JSON.stringify(data)}
put(url) { ... }
{ method: 'PUT', headers: {'Content-type':'application/json'}, body: JSON.stringify(data)}
delete(url) { ... }
{ method: 'DELETE', headers: {'Content-type':'application/json'}
.then(() => resolve("resource deleted)')
async function mFunc() { ... }
mFunc().then((res) => console.log(res));
const promise = new Promise((resolve, reject) => { ... }
setTimeout(() => resolve("hello"), 3000);
const res = await promise;
return res;
await Promise.reject(new Error('show me your cheese'))
async function getPosts() { ... }
const response = await fetch("https://jsonplaceholder.typicode.com/posts");
const data = await response.json();
return data;
getPosts().then((users) => console.log(users));
const posts [ { ... }, { ... } ];
createPost(post);
getPosts();
function createPost(post, callback) { ... }
callback();
createPost({ title: "post2", body: "this is body2" });
function easyHTTP() { this.http = new XMLHttpRequest(); }
easyHTTP.prototype.post = function(url, data, callback) { ... };
this.http.open('POST', url, true);
this.http.setRequestHeader('Content-type', 'application/json');
this.send(JSON.stringify(data));
this.http.onload = function () { callback(response) ... }
easyHTTP.prototype.get = function (url, callback) { ... };
this.http.send();
this.http.open("GET", url, true);
let self = this;
easyHTTP.prototype.put = function(url, data, callback) { ... };
this.http.open('PUT', url, true);
easyHTTP.prototype.delete = function (url, callback) { ... };
this.http.open('DELETE', url, true);
this.send();