aboutsummaryrefslogtreecommitdiffstats
path: root/example_chat.html
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-06 03:54:38 +0900
committeripknHama <ipknhama@gmail.com>2014-08-06 04:07:46 +0900
commita0c93f5b84cc11b30bc6320ac26127832ef8bf7a (patch)
treedc3a51f019b99bf4b4c62201bf6c183a9fb9fa38 /example_chat.html
parent88cc6079cb2ba9790a2d8bb9a5955006bfcc7a16 (diff)
downloadcrow-a0c93f5b84cc11b30bc6320ac26127832ef8bf7a.tar.gz
crow-a0c93f5b84cc11b30bc6320ac26127832ef8bf7a.zip
long polling implementation complete
change `res handle(req)' into `void handle(req, res)' connnection::handle is divide into two part: before and after user handler
Diffstat (limited to 'example_chat.html')
-rw-r--r--example_chat.html48
1 files changed, 48 insertions, 0 deletions
diff --git a/example_chat.html b/example_chat.html
new file mode 100644
index 0000000..0fe35dd
--- /dev/null
+++ b/example_chat.html
@@ -0,0 +1,48 @@
+<html>
+<head>
+<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
+</head>
+<body>
+<input id="msg" type="text">
+<button id="send">Send</button>
+<div id="logs">
+</div>
+<script>
+$(document).ready(function(){
+ $("#send").click(function(){
+ var msg = $("#msg").val();
+ console.log(msg);
+ if (msg.length > 0)
+ $.post("/send", msg);
+ $("#msg").val("");
+ });
+ $("#msg").keyup(function(event){
+ if(event.keyCode == 13){
+ $("#send").click();
+ }
+ });
+ var lastLog = 0;
+ var updateLog;
+ updateLog = function(data)
+ {
+ console.log("recv ");
+ console.log(data);
+ var lastLog = data.last*1;
+ console.log("lastLog: " + lastLog);
+ var s = "";
+ for(var x in data.msgs)
+ {
+ s += data.msgs[x] + "<BR>";
+ }
+ $("#logs").html(s+$("#logs").html());
+ var failFunction;
+ failFunction = function(){
+ $.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
+ };
+ $.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
+ }
+ $.getJSON("/logs", updateLog);
+});
+</script>
+</body>
+</html>