File size: 653 Bytes
2d80f74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// client-side js
// run by the browser each time your view template is loaded

// by default, you've got jQuery,
// add other scripts at the bottom of index.html

$(function () {
  console.log("hello world :o");

  $.get("/dreams", function (dreams) {
    dreams.forEach(function (dream) {
      $("<li></li>").text(dream).appendTo("ul#dreams");
    });
  });

  $("form").submit(function (event) {
    event.preventDefault();
    var dream = $("input").val();
    $.post("/dreams?" + $.param({ dream: dream }), function () {
      $("<li></li>").text(dream).appendTo("ul#dreams");
      $("input").val("");
      $("input").focus();
    });
  });
});