Comments now submit via fetch() when JS is available, returning JSON instead of triggering a full page reload that kills video/audio playback. Falls back to the existing POST+redirect when JS is disabled.
1.3 KiB
1.3 KiB
MPS-0: AJAX Comment Submission (No Page Refresh)
Problem
When playing video or audio on product/content pages, leaving a comment
triggers a full page reload (POST /comments/new followed by HTTPFound
redirect). This kills media playback mid-stream.
Solution
Progressive enhancement: when JavaScript is available, intercept the comment
form submission and use fetch() with the X-Requested-With: XMLHttpRequest
header. The server detects this header and returns JSON instead of a redirect.
The client inserts the new comment into the DOM without reloading.
When JavaScript is disabled, the existing form POST and redirect behaviour is unchanged.
Files Changed
| File | Change |
|---|---|
make_post_sell/views/comment.py |
Return JSON when AJAX header is present |
make_post_sell/static/js/comments.js |
New: fetch-based form handler, DOM insertion |
make_post_sell/templates/snippets/comments.j2 |
Add id="comments-list", load comments.js |
make_post_sell/tests/test_functional.py |
AJAX comment endpoint tests |
Verification
make test-- all existing and new tests pass- Play a video, leave a comment, video keeps playing
- Disable JS, leave a comment, redirect behaviour works as before
- Comment count updates without reload
- Pending-approval banner shows for non-auto-approved comments