Merge pull request #450 from BuhtigithuB/patch-8

coding utf8 and improve comment
This commit is contained in:
mdipierro
2014-05-26 22:29:56 -05:00
+8 -6
View File
@@ -1,4 +1,6 @@
# -*- coding: utf8 -*-
#!/usr/bin/env python
"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdip...@cs.depaul.edu>
@@ -17,13 +19,13 @@ Attention: Requires Chrome or Safari. For IE of Firefox you need https://github.
3) from any web2py app you can post messages with
from gluon.contrib.websocket_messaging import websocket_send
websocket_send('http://127.0.0.1:8888','Hello World','mykey','mygroup')
websocket_send('http://127.0.0.1:8888', 'Hello World', 'mykey', 'mygroup')
4) from any template you can receive them with
<script>
$(document).ready(function(){
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',function(e){alert(e.data)}))
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup', function(e){alert(e.data)}))
alert("html5 websocket not supported by your browser, try Google Chrome");
});
@@ -35,7 +37,7 @@ Or if you want to send json messages and store evaluated json in a var called da
<script>
$(document).ready(function(){
var data;
$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',function(e){data=eval('('+e.data+')')});
$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup', function(e){data=eval('('+e.data+')')});
});
</script>
@@ -49,11 +51,11 @@ Or if you want to send json messages and store evaluated json in a var called da
Here is a complete sample web2py action:
def index():
form=LOAD('default','ajax_form',ajax=True)
form=LOAD('default', 'ajax_form', ajax=True)
script=SCRIPT('''
jQuery(document).ready(function(){
var callback=function(e){alert(e.data)};
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup',callback))
if(!$.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/mygroup', callback))
alert("html5 websocket not supported by your browser, try Google Chrome");
});
@@ -65,7 +67,7 @@ Here is a complete sample web2py action:
if form.accepts(request,session):
from gluon.contrib.websocket_messaging import websocket_send
websocket_send(
'http://127.0.0.1:8888',form.vars.message,'mykey','mygroup')
'http://127.0.0.1:8888', form.vars.message, 'mykey', 'mygroup')
return form
Acknowledgements: