我以前使用的是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);
}
}
這是所有與您的項目相關的代碼? –
是的,這就是SignalR上的所有內容,其中包含TestHub.cs,另一部分用於發佈消息,但我認爲這不是問題的原因。 – k80sg
首先,如果您使用的是1.0 Alpha版,那麼您的集線器設置錯誤。有關1.0版本的更改,請參閱http://weblogs.asp.net/davidfowler/。 例如hub.showMessage = fu ....將會是hub.client.showMessage = fu .... –