我在获取 SignalR 服务器端集线器代码以调用 JS 客户端方法时遇到问题。我收到此错误消息无法读取未定义的属性“客户端”并且找不到此文件夹http://localhost:8087/signalr/hubs。我一直非常小心地避免明显的陷阱,但我想我仍然忽略了一些东西,我按照此链接中的步骤进行操作https://docs.microsoft.com/en-us/aspnet/signalr/overview/入门/教程入门与信号。这是我的代码:这个 ChatHub 类:public class ChatHub : Hub{ public async Task SendMessage(string user, string message) { await Clients.All.SendAsync("ReceiveMessage", user, message); }}这个 html 页面:<div class="container"> <input type="text" id="message" /> <input type="button" id="sendmessage" value="Send" /> <input type="hidden" id="displayname" /> <ul id="discussion"></ul></div><script src="Scripts/jquery-1.10.2.js"></script><script src="Scripts/jquery.signalR-2.4.1.min.js"></script><script src="signalr/hubs"></script><script type="text/javascript"> $(function () { // Declare a proxy to reference the hub. var chat = $.connection.chatHub; // Create a function that the hub can call to broadcast messages. chat.client.broadcastMessage = function (name, message) { // Html encode display name and message. var encodedName = $('<div />').text(name).html(); var encodedMsg = $('<div />').text(message).html(); // Add the message to the page. $('#discussion').append('<li><strong>' + encodedName + '</strong>: ' + encodedMsg + '</li>'); };
添加回答
举报
0/150
提交
取消