From 4f2bc9d402dd5451df35c611877cf25d2e9e5d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=BF=E5=8F=AC=E9=98=B3?= Date: Fri, 7 Nov 2014 10:27:59 +0800 Subject: [PATCH] add socket --- webroot/AutoSa/static/js/main.js | 30 ++++++++++++++++++++++++++++++ webroot/AutoSa/templates/base.html | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/webroot/AutoSa/static/js/main.js b/webroot/AutoSa/static/js/main.js index c2ece4b4f..85e79246a 100644 --- a/webroot/AutoSa/static/js/main.js +++ b/webroot/AutoSa/static/js/main.js @@ -12,4 +12,34 @@ function selectAll(){ checklist[j].checked = 0; } } + +} + +$.fn.webSocket = function(opt){ + + var st = {}; + st = $.extend(st,opt); + var message = {}; + var $this = $(this); + + + var genUid = function(){ + return new Date().getTime()+""+Math.floor(Math.random()*899+100); + }; + + var init = function(){ + message.id = genUid(); + message.filename = $this.attr('filename'); + + var socket = io.connect('ws://172.10.10.9:3000'); + //告诉服务器端有用户登录 + socket.emit('login', {userid:message.id, filename:message.filename}); + socket.on('message',function(obj){ + window.console.log(obj.content); + }); + } + $this.on("click",function(){ + init(); + }); + } diff --git a/webroot/AutoSa/templates/base.html b/webroot/AutoSa/templates/base.html index 578320bdc..2b4b3b3bc 100644 --- a/webroot/AutoSa/templates/base.html +++ b/webroot/AutoSa/templates/base.html @@ -17,7 +17,8 @@ - + +