jonathanjordan21 commited on
Commit
242c0bc
·
verified ·
1 Parent(s): 877744d

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +30 -26
app.js CHANGED
@@ -96,32 +96,36 @@ async function handleSubmit() {
96
  const btn = document.getElementById("submitBtn");
97
  btn.disabled = true;
98
 
99
- const response = await fetch("https://jonathanjordan21-atm-location-api.hf.space/predict", {
100
- method: "POST",
101
- headers: {
102
- "Content-Type": "application/json",
103
- "Authorization" : "Bearer " + apiKey
104
- },
105
- body: JSON.stringify(payload)
106
- });
107
-
108
- // if (!response.ok) {
109
- // const text = await response.text();
110
- // throw new Error(text || "Request failed");
111
- // }
112
-
113
- const result = await response.json();
114
- console.log("API response:", result);
115
-
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
-
124
- btn.disabled = false
 
 
 
 
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