Skip to content
Myr

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 file

Take it

Started chat examplevisionmediabefore adoption654c526

line 1why, one step back
1%h1 Chat

Added chat example (though not practical over http)visionmediabefore adoption9c5552c

line 2why, one step back
2 %ul#messages

Started chat examplevisionmediabefore adoption654c526

lines 3–6why, one step back
3 %form{ method: 'post' }
4 %input{ type: 'hidden', name: '__method__', value: 'put' }5 %input{ type: 'text', name: 'message' }6 %input{ type: 'submit', value: 'Send' }

Added chat example (though not practical over http)visionmediabefore adoption9c5552c

lines 7–31why, one step back
7 :javascript
8 $(function(){9 // Send message10 $('form').submit(function(){11 var message = $('input[name=message]')12 if (message.val()) 13 $.post('/chat', { message: message.val() }, function(){14 message.val('')15 })16 else17 message.css('border', '1px solid red')18 return false19 })20 21 // Poll22 setInterval(function(){23 $.getJSON('/chat/messages', function(messages){24 $('#messages').empty()25 $.each(messages, function(i, msg){26 $('#messages')27 .append('<li>' + msg + '</li>')28 })29 })30 }, 400)31 })