diff options
author | Joey Hess <joey@kitenet.net> | 2012-07-26 17:56:24 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-07-26 17:56:24 -0400 |
commit | 9fd03c65f9ebee437317a21e27afb600d9815209 (patch) | |
tree | 9799150f582e59d8a343e9ceaebce3dc65897605 /templates/longpolling.julius | |
parent | e79198aacbb7891b0b7a4d156160a1524038e18c (diff) |
webapp now does long polling
The webapp is now a constantly updating clock! I accomplished this amazing
feat using "long polling", with some jquery and a little custom java
script.
There are more modern techniques, but this one works everywhere.
Diffstat (limited to 'templates/longpolling.julius')
-rw-r--r-- | templates/longpolling.julius | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/templates/longpolling.julius b/templates/longpolling.julius new file mode 100644 index 000000000..38ecbc77d --- /dev/null +++ b/templates/longpolling.julius @@ -0,0 +1,25 @@ +// Uses long-polling to update a div with id=poll. +// The PollR route should return a new div, also with id=poll. + +(function( $ ) { + +$.LongPoll = (function() { + return { + send : function() { + $.ajax({ + 'url': '@{PollR}', + 'dataType': 'html', + 'success': function(data, status, jqxhr) { + $('#poll').replaceWith(data); + setTimeout($.LongPoll.send, 3000); + }, + }); + } + } +}()); + +$(document).bind('ready.app', function() { + setTimeout($.LongPoll.send, 40); +}); + +})( jQuery ); |