-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-update.html
More file actions
39 lines (38 loc) · 1.12 KB
/
test-update.html
File metadata and controls
39 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!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>Test Insert</title>
</head>
<body>
<input type="number" id="id">
<input type="text" id="name">
<input type="number" id="groese">
<button id="go">add</button>
</body>
<script>
const id = document.getElementById('id');
const del = document.getElementById('go').addEventListener('click', async ev=>{
let message = '';
const response = await fetch(`/test/${id.value}`, {
method: 'PUT',
body: JSON.stringify({
Name: document.getElementById('name').value,
size: parseFloat(document.getElementById('groese').value)
})
});
if( !response.ok ) {
message = `Error: ${response.status}`;
} else if( 200 <= response.status && response.status <= 299 ) {
//success
result = await response.json();
message = `${response.statusText} ${result.id} ${result.result}`;
} else {
message = `Error: ${response.status}`;
}
alert(message);
});
</script>
</html>