Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents default for form submission #9

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="relative">
<h1 class="text-2xl font-bold text-gray-700 mb-2">Welcome to the Home Page</h1>
{% if is_authenticated %}
<form action="/playlist" method="post" class="pt-2">
<form id="sentence-form" action="/playlist" method="post" class="pt-2">
{% else %}
<form action="/login" method="get" class="pt-2">
{% endif %}
Expand Down Expand Up @@ -39,5 +39,22 @@ <h1 class="text-2xl font-bold text-gray-700 mb-2">Welcome to the Home Page</h1>
</div>
</div>
</div>
<script>
document.getElementById('sentence-form').addEventListener('submit', function(e) {
e.preventDefault(); // This will prevent the default form submission

const formData = new FormData(this);
fetch('/playlist', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log(data); // Process your response here
})
.catch(error => console.error('Error:', error));
});
</script>

</body>
</html>