Skip to content
Myr

app.js

This file

Path

examples/chat/public/javascripts/app.js

28 lines · 696 bytes · JavaScript

Last changed by

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

History of this file

Take it

Merge branch 'master' of git://github.com/visionmedia/expressciaranjbefore adoption046bee8

lines 1–28why, one step back
1
2$(function(){3 // Send message4 $('form').submit(function(){5 var message = $('input[name=message]'),6 name = $('input[name=name]')7 if (message.val()) 8 $.post('/chat', { message: $.trim(name.val()) + ': ' + message.val() }, function(){9 message.val('')10 })11 else12 message.css('border', '1px solid red')13 return false14 })15 16 // Longpoll17 ;(function poll(){18 $.getJSON('/chat/messages', function(messages){19 $('#messages').empty()20 $.each(messages, function(i, msg){21 $('#messages')22 .append('<li>' + msg + '</li>')23 .get(0).scrollTop = $('#messages').get(0).scrollHeight24 })25 poll()26 })27 })()28})