homepage.julius 1014 B

1234567891011121314151617181920212223242526272829303132333435
  1. document.getElementById(#{toJSON aDomId}).innerHTML = "This text was added by the Javascript part of the homepage widget.";
  2. $(function() {
  3. $("##{rawJS commentFormId}").submit(function(event) {
  4. event.preventDefault();
  5. var message = $("##{rawJS commentTextareaId}").val();
  6. // (Browsers that enforce the "required" attribute on the textarea won't see this alert)
  7. if (!message) {
  8. alert("Please fill out the comment form first.");
  9. return;
  10. }
  11. // Make an AJAX request to the server to create a new comment
  12. $.ajax({
  13. url: '@{CommentR}',
  14. type: 'POST',
  15. contentType: "application/json",
  16. data: JSON.stringify({
  17. message: message,
  18. }),
  19. success: function (data) {
  20. var newNode = $("<li></li>");
  21. newNode.text(data.message);
  22. console.log(data);
  23. $("##{rawJS commentListId}").append(newNode);
  24. },
  25. error: function (data) {
  26. console.log("Error creating comment: " + data);
  27. },
  28. });
  29. });
  30. });