Created
July 28, 2021 08:05
-
-
Save peterkarn/2741b3dd01fb8a273d712aff17a26059 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!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