This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-insert.html
67 lines (63 loc) · 1.99 KB
/
test-insert.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!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>
<div>
<input type="text" id="name">
<input type="number" id="groese" step="0.05" min="1.60" max="2.60">
<input type="date" id="date">
<button id="ins">add</button>
</div>
<div>
<input type="text" id="iso" placeholder="Kürzel" minlength="3" maxlength="3">
<input type="text" id="country" placeholder="Land">
<button id="ins-land">add</button>
</div>
</body>
<script>
const ins = document.getElementById('ins').addEventListener('click', async ev=>{
const response = await fetch(`/test`, {
method: 'POST',
body: JSON.stringify({
Name: document.getElementById('name').value,
size : parseFloat(document.getElementById('groese').value),
Date: document.getElementById('date').value
})
});
if( !response.ok ) {
const message = `Error: ${response.status}`;
} else if( 200 <= response.status && response.status <= 299 ) {
//success
result = await response.json();
message = `${response.statusText} ${result.id} `;
} else {
const message = `Error: ${response.statusText}`;
}
alert(message);
});
const del = document.getElementById('ins-land').addEventListener('click', async ev=>{
const response = await fetch(`/country`, {
method: 'POST',
body: JSON.stringify({
ISO: document.getElementById('ISO').value,
Country: document.getElementById('country').value
})
});
if( !response.ok ) {
const message = `Error: ${response.status}`;
} else if( 200 <= response.status && response.status <= 299 ) {
//success
result = await response.json();
message = `${response.statusText} ${result.id} `;
} else {
const message = `Error: ${response.statusText}`;
}
alert(message);
});
</script>
</html>