我正在从链接SignalR旁边学习实现Asp.Net信号MVC4的基础知识。正如教程所建议的那样,我已经实现了一个演示应用程序,但是我无法解决以下错误。
Uncaught :signalR(.).starting(.).sending不是函数
到目前为止,这就是我所尝试的。
先决条件:
集线器
namespace SignalRChat.Hubs
{
public class ChatHub : Hub
{
public void Send( string name, string message )
{
Clients.All.addNewMessageToPage( name, message );
}
}
}Owin启动
[assembly: OwinStartup( typeof( SignalRChat.Startup ) )]
namespace SignalRChat
{
public class Startup
{
public void Configuration( IAppBuilder app )
{
app.MapSignalR();
}
}
}控制器
public ActionResult Chat()
{
return View();
}视图(聊天)
@{
ViewBag.Title = "Chat";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Chat</h2>
<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>
@section scripts {
<!--Script references. -->
<!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
<!--Reference the SignalR library. -->
@*<script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>*@
<script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.0.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
<!--SignalR script to update the chat page and send messages.-->
<script type="text/javascript">
$(function () {
var connection = $.connection('/echo');
console.log(connection);
// Reference the auto-generated proxy for the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call back to display messages.
chat.client.addNewMessageToPage = function (name, message) {
// Add the message to the page.
$('#discussion').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
</script>
}我无法解决以下错误。因为我已经安装了所有必需的文件,并且使用了最新的Jquery,所以这里缺少什么吗?我尝试使用较低版本的signalR,但问题仍然存在。
这里,包含错误列表的开发人员控制台的快照。

误差源

发布于 2016-02-29 05:25:02
我终于解决了我在问题中提到的例外情况。实际上,我已经不必要地安装了WebAPIDoodle.SignalR dll。我已经转储了这个项目,并开始了一个新的项目,一个新的项目设置完成后,我去了软件包控制台管理器,并一个接一个地更新了以下dll。
Rest过程与教程建议的创建owin启动类和集线器类相同。这样做,应用程序就像教程中提到的那样工作得非常完美。我注意到,两个项目signalr自动生成的javascript都是不同的,我猜这是因为以前我不必要地安装了WebAPIDoodle.SignalR dll,这给了我一个不同的javascript。
发布于 2019-05-02 01:59:51
您不应该使用“发送”,而应该使用“发送”,因为在“charthub.cs”文件中,您已经声明了“公共无效发送(.)”javascript myhub.cs
https://stackoverflow.com/questions/35658373
复制相似问题