<!DOCTYPE html>
|
<html>
|
<head>
|
<meta charset="utf-8" />
|
<title></title>
|
<script src="Scripts/jquery-1.6.4.min.js"></script>
|
<script src="Scripts/jquery.signalR-2.4.2.min.js"></script>
|
<script src="http://localhost:8082/SRMAPI/signalr/hubs"></script>
|
<script type="text/javascript">
|
$(function () {
|
// 引用自动生成的集线器代理
|
var chat = $.connection.chatHub;
|
// 定义服务器端调用的客户端sendMessage来显示新消息
|
chat.client.Send = function (title, message) {
|
// 向页面发送接收的消息
|
MsgCount();
|
var html = "<div>标题:" + title + "消息内容:" + message + "</div>";
|
$("#msgcontent").after(html);
|
};
|
// 集成器连接开始
|
$.connection.hub.start().done(function () {
|
MsgCount();
|
});
|
});
|
function MsgCount() {
|
var options = {
|
url: 'Message/MsgCount',
|
type: 'post',
|
async: false,
|
success: function (data) {
|
console.log(data);
|
$("#count").html(data.count);
|
}
|
};
|
$.ajax(options);
|
}
|
</script>
|
</head>
|
<body>
|
<h2>
|
接收消息
|
</h2>
|
|
<div>
|
<label>我的消息:</label>
|
<span style=" color: red; font-size: 30px; margin-right:10px;" id="count"></span>条
|
<br />
|
<br />
|
<div id="msgcontent"></div>
|
</div>
|
</body>
|
</html>
|