2012-12-11 30 views
3

我以前使用的是signalR.js的旧版本,一切都很好,除了间歇性地导致我的页面挂起,因此我想用它来测试从SignalR github网站下载的更新版本。SignalR + Uncaught TypeError:Object#<Object> has no method'sending'

我尝试以下SignalR的客户端的例子,但在铬检测元件的情况下,

遗漏的类型错误我得到这个错误:对象#有没有方法“发送”。任何人都遇到过这个错误?

<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!"); 
      }); 

TestHub.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); 
     } 
    } 
+0

这是所有与您的项目相关的代码? –

+0

是的,这就是SignalR上的所有内容,其中包含TestHub.cs,另一部分用于发布消息,但我认为这不是问题的原因。 – k80sg

+0

首先,如果您使用的是1.0 Alpha版,那么您的集线器设置错误。有关1.0版本的更改,请参阅http://weblogs.asp.net/davidfowler/。 例如hub.showMessage = fu ....将会是hub.client.showMessage = fu .... –

回答

0

你或许应该使用

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

,而不是

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

如果没有帮助,你应该检查,如果你你的项目中没有任何旧的SignalR库CT:那么删除所有SignalR的dll,并添加:

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

这并在中心电话 枢纽为我的伎俩:)

0

添加服务器或客户端。 服务器。订阅

相关问题