gpt4 book ai didi

signalr.client - SignalR + 未捕获的类型错误 : Object # has no method 'sending'
转载 作者:行者123 更新时间:2023-12-02 05:03:50 25 4
gpt4 key购买 nike

我之前使用的是旧版本的 signalR.js,一切都很好,除了它会间歇性地导致我的页面挂起,因此我想使用从 SignalR github 站点下载的较新版本来测试它。

我尝试按照 SignalR 的客户端示例进行操作,但在 chrome 中检查元素时出现此错误,

未捕获类型错误:对象 # 没有方法“发送”。有人遇到过这个错误吗?

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> 
<script src="/Scripts/jquery.signalR.js" type="text/javascript"> </script>
<script src="signalr/hubs" type="text/javascript"> </script>

var hub = $.connection.testHub;
hub.showMessage = function() {
$("#inboxcount").show();
};

$.connection.hub.start()
.done(function() {
hub.subscribe($('#<%= hdnUserId.ClientID %>').val());
})
.fail(function() {
alert("Could not Connect!");
});

测试中心.cs:

using System.Threading;

{
/// <summary>
/// Test Hub used to demonstrate the key concepts of SignalR
/// </summary>
[SignalR.Hubs.HubName("testHub")]
public class TestHub : SignalR.Hubs.Hub
{
/// <summary>
/// Broadcast the message to all clients
/// </summary>
/// <param name="message">message to be broadcasted</param>
public void Broadcast(string message)
{
this.Clients.showMessage(message);
}

/// <summary>
/// Return a string with the formate, Hello [current user name]
/// </summary>
/// <returns></returns>
public string SayHello()
{
//Context property can be used to retreive HTTP attributes like User
return "Hello " + Context.User.Identity.Name;
}

/// <summary>
/// Simulates a long running process that updates its progress
/// </summary>
public void LongRunningMethod()
{
Thread.Sleep(1000);
this.Caller.showMessage("25% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("50% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("75% Completed");
Thread.Sleep(1000);
this.Caller.showMessage("Done");
}

/// <summary>
/// Subscribe to a given message category
/// </summary>
/// <param name="category">the category to subscribe</param>
public void Subscribe(string category)
{
//Add current connection to a connection group with the name 'category'
this.AddToGroup(category);
}

/// <summary>
/// Publish a message to the given mmessage category
/// </summary>
/// <param name="category">the category to send the message</param>
/// <param name="message">the message to be sent</param>
public void Publish(string category, string message)
{
//Broadcast the message to all connections registered under the group 'category'
this.Clients[category].showMessage(message);
}
}

最佳答案

你可能应该使用

 <script src="@Url.Content("~/signalr/hubs")" type="text/javascript"> </script>

代替

 <script src="signalr/hubs" type="text/javascript"> </script>

如果这没有帮助,您应该检查您的项目中是否没有任何旧的 SignalR 库:因此删除每个 SignalR dll,并添加:

  • Microsoft.AspNet.SignalR.Core
  • Microsoft.AspNet.SignalR.Hosting.AspNet
  • Microsoft.AspNet.SignalR.Hosting.Common

这对我有用:)

关于signalr.client - SignalR + 未捕获的类型错误 : Object #<Object> has no method 'sending' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825732/

25 4 0