48 lines
1.1 KiB
HTML
48 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Lekcja 2.2</title>
|
|
<style>
|
|
#div1 {
|
|
width: 100px;
|
|
height: 100px;
|
|
background-color: cornflowerblue;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="div1">
|
|
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById("div1").onclick = function() {
|
|
const data = JSON.stringify({
|
|
a: 1,
|
|
b: 2,
|
|
})
|
|
|
|
const options = {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: data
|
|
}
|
|
|
|
fetch("/test", options)
|
|
.then(function(response) {
|
|
return response.json();
|
|
})
|
|
.then(function(dataFromServer) {
|
|
alert(JSON.stringify(dataFromServer, null, 5))
|
|
})
|
|
.catch(function(error) {
|
|
console.error(error)
|
|
})
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |