-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_c.js
More file actions
61 lines (53 loc) · 1.65 KB
/
script_c.js
File metadata and controls
61 lines (53 loc) · 1.65 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
52
53
54
55
56
57
58
59
60
61
// Get references to the form and its input fields
const form = document.getElementById('creation-form');
const apiUrlInput = document.getElementById('api-url-input');
const nameInput = document.getElementById('name-input');
const descriptionInput = document.getElementById('description-input');
// Event listener for form submission
form.addEventListener('submit', function (event) {
event.preventDefault(); // Prevent the default form submission
// Get the form data
const apiUrl = apiUrlInput.value;
const name = nameInput.value;
const description = descriptionInput.value;
// Prepare the data to be sent as JSON
const data = {
apiUrl: apiUrl,
name: name,
description: description
};
// Make a POST request to the Flask API
fetch('https://justct.pythonanywhere.com/new', {
method: 'POST',
mode: "cors",
headers: {
'url': apiUrl ,
'name': name ,
'description':description
},
})
.then(response => response.text())
.then(result => {
// Display appropriate CSS popup based on the response
if (result === 'x') {
showPopup('Room already exists');
} else if (result === 's') {
showPopup('Room created successfully');
} else if (result === 'n') {
showPopup('API URL not working');
} else {
showPopup('Unknown response');
}
})
.catch(error => console.error('Error:', error));
});
// Function to display a CSS popup
function showPopup(message) {
const popup = document.createElement('div');
popup.classList.add('popup');
popup.textContent = message;
document.body.appendChild(popup);
setTimeout(() => {
popup.remove();
}, 3000);
}