1
yusijie
2023-03-07 f50ccbe69bd123135e412b00bbcbf732a8b93c77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!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>