reply.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {% load static %}
  2. <!DOCTYPE html>
  3. <html lang="zh-cn">
  4. <head>
  5. <meta charset="utf-8">
  6. <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
  7. </head>
  8. <body>
  9. <form
  10. action="."
  11. method="POST"
  12. id="reply_form"
  13. >
  14. {% csrf_token %}
  15. <div class="form-group">
  16. <div id="test">
  17. {{ comment_form.media }}
  18. {{ comment_form.body }}
  19. </div>
  20. </div>
  21. </form>
  22. <!-- 提交按钮 -->
  23. <button onclick="confirm_submit({{ article_id }}, {{ parent_comment_id }})" class="btn btn-primary">发送</button>
  24. <script src="{% static 'jQuery/jquery-3.5.1.js' %}"></script>
  25. <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1-lts/dist/umd/popper.min.js"></script>
  26. <script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
  27. <!-- csrf token -->
  28. <script src="{% static 'csrf.js' %}"></script>
  29. <script>
  30. $(function () {
  31. $(".django-ckeditor-widget").removeAttr('style');
  32. });
  33. function confirm_submit(article_id, comment_id) {
  34. // 从 ckeditor 中取值
  35. let content = CKEDITOR.instances['id_body'].getData();
  36. // 调用 ajax 与后端交换数据
  37. $.ajax({
  38. url: '/comment/post_comment/' + article_id + '/' + comment_id,
  39. type: 'POST',
  40. data: {body: content},
  41. // 成功回调
  42. success: function (e) {
  43. if (e === '200 OK') {
  44. parent.location.reload();
  45. }
  46. }
  47. })
  48. }
  49. </script>
  50. </body>
  51. </html>