signalR javascript客户端查询字符串

时间:2017-04-17 06:49:19

标签: javascript signalr

我使用signalR。我有一个问题。我不在javascipt客户端创建查询字符串。我该怎么办?

Javascript代码

VK_KHR_XCB_SURFACE_EXTENSION_NAME

服务器代码

$.connection.hub.url = "http://localhost:8090/signalr";

var chat = $.connection.myHub2;
// $.connection.hub.qs = { 'useridbrowser': 'session1' };
$.connection.hub.qs = "useridbrowser= session1";
$.connection.hub.start({ 'useridbrowser': 'session1' 
}).done(function () {
}

我写

public override Task OnConnected()
{            
    mouseqs = Context.QueryString["useridbrowser"];
    return (base.OnConnected());
}

但没有工作

1 个答案:

答案 0 :(得分:0)

请参阅以下javascript:

<script src="Scripts/jquery-1.6.4.min.js" ></script>
<script src="Scripts/jquery.signalR-1.1.4.min.js"></script>
<script src="signalr/hubs"></script>
<script type="text/javascript">
    $(function () {
        var chat = $.connection.CallCenterHub;
        $.connection.hub.qs = { 'ClientType': 'WebUser', 'UserId': $('#txtUserId').val() };

        chat.client.onInstantMessage = function (MessageId, MessageFrom, MessageTo, MessageText, MessageDateTime) {

            if (MessageFrom != $('#txtUserId').val()) {
               $('#txtConnectedUser').val(MessageFrom);
            }


            if (MessageFrom == $('#txtUserId').val()) {
                $('#MessagesArea').append('<div class="well" style = "height:100%;padding-top:1px;padding-left:1px;padding-right:1px;padding-bottom:1px;width:100%;"><table style="width: 100%; table-layout: fixed;"><tr><td width="32px" valign="top"><img src="Images/IM32.png" height="32" width="32"></td><td><table style="width: 100%; table-layout: fixed;"><tr><td><table  style="width: 100%; table-layout: fixed;"><tr><td width="50%"><b>&nbsp;&nbsp;Me:</b></td><td align="right" width="50%">' + MessageDateTime + '</td></tr></table></td></tr><tr><td style = "color: #000000;white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap:break-word;">&nbsp;&nbsp;' + MessageText + '</td></tr></table></td></tr></table></div>');
            }
            else {
                $('#MessagesArea').append('<div class="well" style = "height:100%;padding-top:1px;padding-left:1px;padding-right:1px;padding-bottom:1px;width:100%;"><table style="width: 100%; table-layout: fixed;"><tr><td width="32px" valign="top"><img src="Images/IM2_32.png" height="32" width="32"></td><td><table style="width: 100%; table-layout: fixed;"><tr><td><table  style="width: 100%; table-layout: fixed;"><tr><td width="50%"><b>&nbsp;&nbsp;' + MessageFrom + ':</b></td><td align="right" width="50%">' + MessageDateTime + '</td></tr></table></td></tr><tr><td style = "color: #000000;white-space: pre-wrap;white-space: -moz-pre-wrap;white-space: -pre-wrap;white-space: -o-pre-wrap;word-wrap:break-word;">&nbsp;&nbsp;' + MessageText + '</td></tr></table></td></tr></table></div>');
            }

            var objDiv = document.getElementById("MessagesAreaAll");
            objDiv.scrollTop = objDiv.scrollHeight;

        };

        $('#message').focus();
        $.connection.hub.start().done(function () {
            $('#sendmessage').click(function () {
                chat.server.sendInstantMessage($('#txtUserId').val(), $('#txtConnectedUser').val(), $('#message').val());
                $('#message').val('').focus();
            });
        });

        $('#message').keydown(function (event) {
            if (event.keyCode == 13) {
                chat.server.sendInstantMessage($('#txtUserId').val(), $('#txtConnectedUser').val(), $('#message').val());
                $('#message').val('').focus();
            }
        });

    });
</script>