Update app.js
Browse files
app.js
CHANGED
|
@@ -96,32 +96,36 @@ async function handleSubmit() {
|
|
| 96 |
const btn = document.getElementById("submitBtn");
|
| 97 |
btn.disabled = true;
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
// console.log("Submitted payload:", payload);
|
| 127 |
|
|
|
|
| 96 |
const btn = document.getElementById("submitBtn");
|
| 97 |
btn.disabled = true;
|
| 98 |
|
| 99 |
+
try {
|
| 100 |
+
const response = await fetch("https://jonathanjordan21-atm-location-api.hf.space/predict", {
|
| 101 |
+
method: "POST",
|
| 102 |
+
headers: {
|
| 103 |
+
"Content-Type": "application/json",
|
| 104 |
+
"Authorization" : "Bearer " + apiKey
|
| 105 |
+
},
|
| 106 |
+
body: JSON.stringify(payload)
|
| 107 |
+
});
|
| 108 |
+
|
| 109 |
+
// if (!response.ok) {
|
| 110 |
+
// const text = await response.text();
|
| 111 |
+
// throw new Error(text || "Request failed");
|
| 112 |
+
// }
|
| 113 |
+
|
| 114 |
+
const result = await response.json();
|
| 115 |
+
console.log("API response:", result);
|
| 116 |
+
|
| 117 |
+
document.querySelectorAll("#numberInputs input").forEach(input => {
|
| 118 |
+
const key = input.dataset.key;
|
| 119 |
+
if (key in result) {
|
| 120 |
+
input.value = result[key];
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
} catch (error) {
|
| 124 |
+
alert("An error occurred: " + error.message);
|
| 125 |
+
console.error("Error details:", error);
|
| 126 |
+
} finally {
|
| 127 |
+
btn.disabled = false;
|
| 128 |
+
}
|
| 129 |
|
| 130 |
// console.log("Submitted payload:", payload);
|
| 131 |
|