fix: update scrape function to handle HTML response and improve status messages
This commit is contained in:
@@ -41,12 +41,16 @@ function scrape(event) {
|
|||||||
event.preventDefault(); // Prevent the default form submission
|
event.preventDefault(); // Prevent the default form submission
|
||||||
updateScrapeInfo("Scraping in progress...", "blue");
|
updateScrapeInfo("Scraping in progress...", "blue");
|
||||||
fetch("/scrape")
|
fetch("/scrape")
|
||||||
.then((response) => response.json())
|
// expect HTML response containing "Scraping completed successfully!"
|
||||||
|
.then((response) => response.text())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.status) {
|
if (data.includes("Scraping completed successfully!")) {
|
||||||
updateScrapeInfo(data.status, "green");
|
updateScrapeInfo("Scraping completed successfully!", "green");
|
||||||
} else {
|
} else {
|
||||||
updateScrapeInfo("Scraping failed. Please try again.", "red");
|
updateScrapeInfo(
|
||||||
|
"Scraping failed or timed out. Please try again.",
|
||||||
|
"red"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => console.error("Error:", error));
|
.catch((error) => console.error("Error:", error));
|
||||||
|
|||||||
Reference in New Issue
Block a user