質問

I am learning SignalR (using this tutorial) and have the code from my class. The problem is that when executing the following

this.init = function () {
  this.hub.getAll();
}

I got Uncaught TypeError: Object # has no method 'getAll'. When examine the this.hub I saw that there is no add, update, getAll method. All these methods are one layer inner in thus.hub.server. Why does this.hub.getAll not exist? Is this.hub.getAll() and this.hub.server.getAll() the same thing? I think not because when I change my code to this.hub.server.getAll() the error went away but it did not do what it is supposed to do: loading data.

Here is the script section

@section Scripts {
  @Scripts.Render("~/bundles/knockout")
  @Scripts.Render("~/bundles/signalr")
  <script src="/Scripts/jquery.signalR-2.0.1.min.js" type="text/javascript"></script>
  <script src="signalr/hubs" type="text/javascript"></script>
  <script src="/Scripts/jquery.livequery.min.js"></script>

BundleConfig.cs

    bundles.Add(new ScriptBundle("~/bundles/signalr").Include(
                        "~/Scripts/jquery.signalR-2.0.1.min.js"));

Any ideas?

Thanks,

役に立ちましたか?

解決

The tutorial you're following is based on an older version of SignalR. Back then, hub methods were added directly to the hub object; now, they're added to hub.server to avoid collisions with client-side methods (which are defined on hub.client). So you'll need to call hub.server.getAll() in your case. As to why that's not working, you'll have to provide more detail (probably in a different question), although the first thing you should check is whether you're defining your client-side methods on hub.client instead of on hub, as is done in the tutorial.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top