gpt4 book ai didi

javascript - SignalR 错误 : signalR(. ..).starting(...).sending 不是函数

转载 作者:行者123 更新时间:2023-11-30 00:13:10 26 4
gpt4 key购买 nike

我正在通过链接 Asp.Net Signal MVC4 学习实现 SignalR 的基础知识.就像教程建议的那样,我已经实现了一个演示应用程序,但我无法解决以下错误。

Uncaught TypeError: signalR(...).starting(...).sending is not a function

这是我到目前为止尝试过的。

先决条件:

  1. Microsoft.AspNet.SignalR
  2. WebAPIDoodle.SignalR

中心

namespace SignalRChat.Hubs
{
public class ChatHub : Hub
{
public void Send( string name, string message )
{
Clients.All.addNewMessageToPage( name, message );
}
}
}

欧文创业公司

[assembly: OwinStartup( typeof( SignalRChat.Startup ) )]

namespace SignalRChat
{
public class Startup
{
public void Configuration( IAppBuilder app )
{
app.MapSignalR();
}
}
}

Controller

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,但同样的问题仍然存在。

这里是带有错误列表的开发者控制台快照。

enter image description here

错误来源

enter image description here

最佳答案

我终于解决了我在问题中提到的异常。实际上我不必要地安装了 WebAPIDoodle.SignalR dll。我已经放弃了这个项目,并在新项目设置完成后立即开始一个新项目,我去了包控制台管理器,并逐一更新了以下 dll。

  1. Microsoft.AspNet.SignalR
  2. 微软.Owin
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Host.SystemWeb

其余过程与教程建议创建一个 owin 启动类和一个 hub 类相同。做了这么多,应用程序就像教程中提到的那样完美运行。我注意到的是两个项目 signalr 自动生成的 javascript 是不同的,我想这是因为以前我不必要地安装了 WebAPIDoodle.SignalR dll,这给了我一个不同的 javascript。

关于javascript - SignalR 错误 : signalR(. ..).starting(...).sending 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com