-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.html
More file actions
51 lines (44 loc) · 1.34 KB
/
api.html
File metadata and controls
51 lines (44 loc) · 1.34 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
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Request</title>
</head>
<body>
<h1>API Request</h1>
<button id="apiButton">Send API Request</button>
<script>
const url = 'https://smartside.netlify.app/api'; // Replace with your API endpoint
const data = {
userId: 'super',
pwd: 'qwerty',
role: 'admin'
};
function sendApiRequest() {
fetch(url, {
method: 'POST', // HTTP method
headers: {
'Content-Type': 'application/json', // Setting content type to JSON
},
body: JSON.stringify(data), // Sending the request body as a string
})
.then(response => {
console.log('Response status:', response.status); // Log status
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(result => {
console.log('Success:', result); // Handle success
})
.catch(error => {
console.error('Error:', error); // Handle error
});
}
// Add event listener to the button
document.getElementById('apiButton').addEventListener('click', sendApiRequest);
</script>
</body>
</html>