Powtóreczka
This commit is contained in:
1 parent
e80734527f
commit
c1348ef991
648 files changed
+66782
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Fetch działanie</title>
|
||||
</head>
|
||||
<body>
|
||||
<button id="przycisk">Użyj fetcha</button>
|
||||
<script>
|
||||
const przycisk = document.getElementById('przycisk')
|
||||
|
||||
przycisk.onclick = function() {
|
||||
const data = JSON.stringify({
|
||||
"message": "siema OI"
|
||||
})
|
||||
|
||||
const options = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: data
|
||||
}
|
||||
|
||||
fetch("/test", options)
|
||||
.then(function(response) {
|
||||
return response.json()
|
||||
})
|
||||
.then(function(data) {
|
||||
// tutaj robimy rzeczy z danymi z fetch'a
|
||||
|
||||
// np przypisujemy elementom strony jakieś cechy
|
||||
// na podstawie danych z odpowiedzi
|
||||
przycisk.innerText = data.odpowiedz
|
||||
})
|
||||
.catch(function(error) {
|
||||
console.error(error)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
testgedtegdeede
|
||||
Reference in new issue
Block a user