fixed ttl return data parsing

This commit is contained in:
Russel Yasol
2024-05-10 18:18:04 +08:00
parent 30937e20ba
commit af05f087c7

View File

@@ -650,37 +650,25 @@
fetch( fetch(
"/cgi-bin/set_ttl?" + new URLSearchParams({ ttlvalue: ttlval }) "/cgi-bin/set_ttl?" + new URLSearchParams({ ttlvalue: ttlval })
) )
.then((res) => res.text()) .then((res) => res.text()) // Use res.text() instead of res.json()
.then((data) => { .then((data) => {
// Split the response into JSON and non-JSON parts // Manually handle the response data
const parts = data.trim().split("\n\n"); console.log("Response from server:", data);
const nonJsonPart = parts[0]; // You can try to parse the JSON manually or handle the response as needed
const jsonPart = parts[1];
// Log the non-JSON part // Once TTL is updated, fetch the updated TTL data
console.log("Non-JSON response:", nonJsonPart); this.fetchTTL();
this.isLoading = false; // Set loading state back to false
// Parse the JSON part
try {
const jsonData = JSON.parse(jsonPart);
console.log("JSON response:", jsonData);
// Handle the JSON data as needed
// ...
// Once TTL is updated, fetch the updated TTL data
this.fetchTTL();
this.isLoading = false; // Set loading state back to false
} catch (error) {
console.error("Error parsing JSON:", error);
this.isLoading = false; // Ensure loading state is properly handled in case of error
}
}) })
.catch((error) => { .catch((error) => {
console.error("Error updating TTL: ", error); console.error("Error updating TTL: ", error);
this.isLoading = false; // Ensure loading state is properly handled in case of error this.isLoading = false; // Ensure loading state is properly handled in case of error
}); });
}, },
init() {
this.fetchTTL();
this.fetchCurrentSettings();
},
}; };
} }
</script> </script>