$(function() {
  $('form#chat-form').submit(function(event) {
      event.preventDefault();
      var message = $('input[name="message"]').val();
      if (message.trim() == '') {
          return false;
      }
      $('ul.chat-box').append('<li class="user">' + message + '</li>');
      $('input[name="message"]').val('');
      $.ajax({
          url: '/get-response',
          data: {message: message},
          type: 'POST',
          dataType: 'json',
          success: function(response) {
              $('ul.chat-box').append('<li class="bot">' + response.message + '</li>');
          },
          error: function(error) {
              console.log(error);
          }
      });
  });
});