我试图在索引页面上显示信号r消息。关注枢纽详情
public class TasksHub : Hub
{
public void NewTaskDetails(int taskid,string taskname,string created,string role)
{
Clients.All.addMessage(taskid, taskname, created, role);
}
}
my error is : Unhandled exception at line 60, column 9 in http://localhost:45845/
0x800a138f-JavaScript runtime error:
无法获取未定义或空引用的属性TasksHub
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.signalR-1.1.0.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
$(function ()
{
var THub = $.connection.TasksHub;
$messages = $("#messages");
THub.client.send = function (taskid, taskname, created, role) {
$messages.append("<br /><b>" + taskid + ":</b>" + taskname);
}
$.connection.THub.start();
});
答案 0 :(得分:0)
使用Camel Casing
例如,如果类名为MyChatHub
然后你应该打电话给var chat = $.connection.myChatHub;
希望它有所帮助并确保加载所有脚本文件并检入Global.asax文件 加入
RouteTable.Routes.MapHubs();