SignalR Updating TextArea realtime

浪尽此生 提交于 2019-12-08 05:02:34

问题


Hi i just started learning SignalR v2. I have a textarea in my aspx page and i want to update it in realtime whenever a user presses a key on it.

Issue: I opened 2 tabs in my browser. If i type the first character example "a", nothing happens: Tab1 textarea: "a" tab2 textarea: NOTHING

Then i proceed to type the second character "b" Tab1 textarea: "ab" tab2 textarea: "a"

Conclude: Its always not updating the latest character i typed!

SignalR Class

 public class DocHub : Hub
    {
       public void Update(String text)
       {
           this.Clients.Others.updateText(text);
       }
    }

index.aspx

<body>
    <form id="form1" runat="server">
    <div style="font-size:50px;"> New Document</div>
    <textarea rows="4" cols="50" id="ta"></textarea>

    <script src="Scripts/jquery-1.10.2.js"></script>
    <script src="Scripts/jquery.signalR-2.1.2.js"></script>
    <script src="signalr/hubs"></script>

    <script type="text/javascript">
        $(function () {
            var hubProxy = $.connection.docHub;
            hubProxy.client.updateText = function (msg) {
                $("#ta").val(msg);
            };
            $("#ta").keydown(function () {
                hubProxy.server.update($("#ta").val());
            });

            $.connection.hub.start();

        });
    </script>
    </form>
</body>

回答1:


I really would try to use keyup instead



来源:https://stackoverflow.com/questions/30326904/signalr-updating-textarea-realtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!