Promise example #5
by mbychawski
HTML
<div id="log"></div>
CSS
body {
font-family: monospace;
}
Babel + JSX
Promise.resolve()
.then(()=>{
log('onFulfilled#1 returns thenable');
return $.post({
url: '/echo/json/',
data: {json: JSON.stringify({hello: 'from server'}), delay: 1},
crossDomain: true
});
})
.then((value)=>{
console.log(value);
log('onFulfilled#2 got value:', JSON.stringify(value));
});
function log(...strings){
let node = document.createElement('div');
node.innerText = strings.join(' ');
document.getElementById('log').appendChild(node);
}