client.js 647 B

123456789101112131415161718192021222324252627
  1. // client-side js
  2. // run by the browser each time your view template is loaded
  3. // by default, you've got jQuery,
  4. // add other scripts at the bottom of index.html
  5. $(function() {
  6. console.log('hello world :o');
  7. $.get('/dreams', function(dreams) {
  8. dreams.forEach(function(dream) {
  9. $('<li></li>').text(dream).appendTo('ul#dreams');
  10. });
  11. });
  12. $('form').submit(function(event) {
  13. event.preventDefault();
  14. dream = $('input').val();
  15. $.post('/dreams?' + $.param({'dream': dream}), function() {
  16. $('<li></li>').text(dream).appendTo('ul#dreams');
  17. $('input').val('');
  18. $('input').focus();
  19. });
  20. });
  21. });