chat.haml.html
This file
Path
examples/views/chat.haml.html
31 lines · 866 bytes · HTML
Last changed by
Added chat example (though not practical over http)visionmediabefore adoption9c5552c
History of this fileTake it
12345678910111213141516171819202122232425262728293031%h1 Chat %ul#messages %form{ method: 'post' } %input{ type: 'hidden', name: '__method__', value: 'put' } %input{ type: 'text', name: 'message' } %input{ type: 'submit', value: 'Send' } :javascript $(function(){ // Send message $('form').submit(function(){ var message = $('input[name=message]') if (message.val()) $.post('/chat', { message: 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>') }) }) }, 400) })