Skip to content

Instantly share code, notes, and snippets.

@peterkarn
Created July 28, 2021 08:05
Show Gist options
  • Save peterkarn/2741b3dd01fb8a273d712aff17a26059 to your computer and use it in GitHub Desktop.
Save peterkarn/2741b3dd01fb8a273d712aff17a26059 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Возврат от серваера
<pre class="fetch">
</pre>
<hr>
</body>
<script>
//get-запрос - без параметров
fetch('https://jsonplaceholder.typicode.com/todos/23')
.then(response => response.json()) //обработка ответа методом .json() - встроенный метод fetch - возвращает promiss
.then(json => console.log(json))
//POST
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
name: 'Al',
b: 'test'
}),
headers: {
'Content-type': 'application/JSON'
}
})
.then(response => response.text())
.then(json => document.querySelector('.fetch').innerHTML = json)
// =============================================================== //
const getResource = async () => {
};
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment