Browse Source

Listing 20: adding comments - submit to server.

Frederic G. MARAND 8 years ago
parent
commit
2e72dee5ba
2 changed files with 15 additions and 1 deletions
  1. 3 0
      .gitignore
  2. 12 1
      public/scripts/tutorial.js

+ 3 - 0
.gitignore

@@ -32,3 +32,6 @@ node_modules
 *~
 .DS_Store
 Thumbs.db
+
+# Compiled server
+server

+ 12 - 1
public/scripts/tutorial.js

@@ -87,7 +87,18 @@ let CommentBox = React.createClass({
     return { data: [] };
   },
   handleCommentSubmit: function (comment) {
-    // TODO send request to the server and refresh the list.
+    $.ajax({
+      url: this.props.url,
+      dataType: "json",
+      type: "POST",
+      data: comment,
+      success: function (data) {
+        this.setState({ data: data });
+      }.bind(this),
+      error: function (xhr, status, err) {
+        console.error(this.props.url, status, err.toString());
+      }
+    });
   },
   loadCommentsFromServer: function () {
     $.ajax({