This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('./api/some.json') | |
.then( | |
function(response) { | |
if (response.status !== 200) { | |
console.log('Looks like there was a problem. Status Code: ' + | |
response.status); | |
return; | |
} | |
// Examine the text in the response | |
response.json().then(function(data) { | |
console.log(data); | |
}); | |
} | |
) | |
.catch(function(err) { | |
console.log('Fetch Error :-S', err); | |
}); | |
// Post | |
fetch(url, { | |
method: 'post', | |
headers: { | |
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8" | |
}, | |
body: 'foo=bar&lorem=ipsum' | |
}) | |
.then(json) | |
.then(function (data) { | |
console.log('Request succeeded with JSON response', data); | |
}) | |
.catch(function (error) { | |
console.log('Request failed', error); | |
}); |
No comments:
Post a Comment