app.js
This file
Path
examples/public/app.js
27 lines · 687 bytes · JavaScript
Last changed by
Moved app js into public/app.jsvisionmediabefore adoption4721b9c
History of this fileTake it
123456789101112131415161718192021222324252627
$(function(){ // Send message $('form').submit(function(){ var message = $('input[name=message]'), name = $('input[name=name]') if (message.val()) $.post('/chat', { message: $.trim(name.val()) + ': ' + message.val() }, function(){ message.val('') }) else message.css('border', '1px solid red') return false }) // Poll setInterval(function(){ $.getJSON('/chat/messages', function(messages){ $('#messages').empty() $.each(messages, function(i, msg){ $('#messages') .append('<li>' + msg + '</li>') .get(0).scrollTop = $('#messages').get(0).scrollHeight }) }) }, 400)})