signalR消息实时推送
2015-06-09 17:53
323 查看
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>SignalR Simple Chat</title> <style type="text/css"> .container{ background-color:#99ccFF; border:thick solid #808080; padding:20px; margin:20px; } </style> </head> <body> <div class="container "> <input type="text" id="mm"/> <input type="button" id="gg" value="Send " /> <input type="hidden" id="nn" /> <ul id="discussion"> </ul> </div> <script src="Scripts/jquery-1.7.1.min.js"></script> <script src="Scripts/jquery.signalR-2.2.0.min.js"></script> <script src="/signalr/hubs"></script> <script type="text/javascript"> $(function () { // Declare a proxy to reference the hub. var chat = $.connection.chatHub; // Create a function that the hub can call to broadcast messages. chat.client.broadcastMessage = function (name, message) { // Html encode display name and message. var encodedName = $('<div />').text(name).html(); var encodedMsg = $('<div />').text(message).html(); // Add the message to the page. $('#discussion').append('<li><strong>' + encodedName + '</strong>: ' + encodedMsg + '</li>'); }; // Get the user name and store it to prepend to messages. $('#nn').val(prompt('Enter your name:', '')); // Set initial focus to message input box. $('#mm').focus(); // Start the connection. $.connection.hub.start().done(function () { $('#gg').click(function () { // Call the Send method on the hub. chat.server.send($('#nn').val(), $('#mm').val()); // Clear text box and reset focus for next comment. $('#mm').val('').focus(); }); }); }); </script> </body> </html>
View Code
相关文章推荐
- 定时器
- 软件架构杂谈(四) --- P2P
- SurfaceView播放视频遇到的bug
- C++中四种强制类型转换
- 第14周阅读项目-掌握标准输入输出流的控制
- android shape的使用
- MDT 2013 从入门到精通之自动化部署配置
- 会签的并发控制
- Android设计模式(九)--外观模式
- 为什么编译tiny工程出错,提示"不兼容的类型"
- Tiny框架的应用定位
- 为什么我写的page页面无法渲染
- Echarts同一页面多个图表自适应浏览器窗口大小——window.onresize
- PHP array_diff()
- IOS 提示Unsupported Configuration
- javascript闭包
- 关于UIImagePickerController的理解 (区别于上文的AVCapture)
- [leetcode] 83.Remove Duplicates from Sorted List
- 在Eclipse中导入Tiny工程,有下面的错误,是什么原因?
- 学习TINY需要多长时间?