<!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) {
|
// 向页面发送接收的消息
|
sendMsg();
|
};
|
// 集成器连接开始
|
$.connection.hub.start().done(function () {
|
sendMsg();
|
// 服务连接完成,给发送按钮注册单击事件
|
$('#sendmessage').click(function () {
|
// 调用服务器端集线器的Send方法
|
chat.server.send($("#title").val(), $('#message').val());
|
});
|
});
|
});
|
|
function sendMsg() {
|
var options = {
|
url: "Message/MsgCount",
|
type: 'post',
|
success: function (data) {
|
$("#count").html(data.count);
|
}
|
};
|
$.ajax(options);
|
}
|
</script>
|
</head>
|
<body>
|
<h2>
|
发送消息
|
</h2>
|
<div>
|
<label>我的消息:</label>
|
<span style=" color:red; font-size:30px;" id="count"></span>条
|
</div>
|
<p>
|
<div>
|
标题:
|
<input type="text" id="title" />
|
</div>
|
<br /><br />
|
<div>
|
内容:
|
<textarea id="message" rows="4" cols="30"></textarea>
|
</div>
|
<br /><br />
|
<div>
|
<input type="button" id="sendmessage" value="发送" />
|
</div>
|
</p>
|
</body>
|
</html>
|