digitalicfai / static /courses.js
Chaitu2112's picture
Add project files (exclude local DBs, indexes and secrets)
74d9449
raw
history blame contribute delete
909 Bytes
const courseForm = document.getElementById("course-form");
const courseResults = document.getElementById("course-results");
courseForm.addEventListener("submit", async (e) => {
e.preventDefault();
courseResults.innerHTML = "<p><em>Generating recommendations...</em></p>";
const formData = new FormData(courseForm);
try {
const res = await fetch("/recommend", { method: "POST", body: formData });
const data = await res.json();
if (data.recommendations && data.recommendations.length > 0) {
courseResults.innerHTML = `
<h3>Recommended Courses:</h3>
<ul>
${data.recommendations.map(c => `<li>${c}</li>`).join("")}
</ul>
`;
} else {
courseResults.innerHTML = "<p>No matching courses found.</p>";
}
} catch (err) {
courseResults.innerHTML = "<p>⚠️ Error fetching recommendations.</p>";
console.error(err);
}
});