summaryrefslogtreecommitdiff
path: root/templates/homepage.julius
blob: 865882ec95906377596add8696a1bd48a85c169c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
document.getElementById(#{toJSON aDomId}).innerHTML = "This text was added by the Javascript part of the homepage widget.";

$(function() {
  $("##{rawJS commentFormId}").submit(function(event) {
    event.preventDefault();

    var message = $("##{rawJS commentTextareaId}").val();
    // (Browsers that enforce the "required" attribute on the textarea won't see this alert)
    if (!message) {
      alert("Please fill out the comment form first.");
      return;
    }

    // Make an AJAX request to the server to create a new comment
    $.ajax({
      url: '@{CommentR}',
      type: 'POST',
      contentType: "application/json",
      data: JSON.stringify({
        message: message,
      }),
      success: function (data) {
        var newNode = $("<li></li>");
        newNode.text(data.message);
        console.log(data);
        $("##{rawJS commentListId}").append(newNode);
      },
      error: function (data) {
        console.log("Error creating comment: " + data);
      },
    });

  });
});