If you’d like to ajaxify your WordPress comment form, here’s the easy way to do it:
1. Add “submitting comment” message:
Add inline style to hide it. This will be displayed when user submitting comment for UX reason.
The path to file is made based on the assumption that this solution will be used as standalone plugin:
3. Send comment as AJAX call
What this script basically does1:
- Prevent comment form’s default behaviour.
- Display the submitting comment message added on step no.1
- Submit the comment form inputs using
- If the comment is successfully received, replace the comment area with comment area on the
responseTextwhich actually the HTML text of the submitted comment
- If an error occurred, translate the
xhr.statusinto understandable error message
Here’s how it looks: