I will try to send data to the server whit SignalR 2. But I get this error:
Uncaught TypeError: Cannot read property 'meldingenHub' of undefined
Here is the C# code on the server:
public class MeldingenHub : Hub
{
public void Meld(string blogitem, string verdiendePunten)
{
Clients.All.BroadcastMessage(blogitem, verdiendePunten);
}
}
Here I include all the file that is needed:
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="~/signalr/hubs"></script>
Here is the Client code that gives the error on the bold code.
var medlingenHub = $.connection.meldingenHub; medlingenHub.client.broadcastMessage = function (blogitem, verdiendePunten) { $("#verdiendepunten").html(verdiendePunten); }; $.connection.hub.start().done(function () { var json = { ID: parseInt(this.dataset.id), Type: this.dataset.type, GebruikerID: "@(Model.DeBlog.Gebruiker.Id)", Punten: parseInt(this.dataset.punten), GestemdeGebruikerID: "@(Model.AangemeldeGebruiker)" }; $.ajax({ url: "../api/Stem/[email protected]", type: "PUT", data: json, success: function (returnData) { if (returnData.Oke == false) { toonError(returnData) } else { plaatsKleuren(returnData); medlingenHub.server.meld(data.ID, data.Punten); } } }); });
Note by the code above: the code executes when I click on a button.
I've also added this line on the Startup.Auth.cs
file:
public void ConfigureAuth(IAppBuilder app)
{
app.MapSignalR();
// other code
}
I follow a tutorial on asp.net. Can anyone help me?
[HubName("meldingenHub")]
for your hub? – Sirwan AfifiHubName
attribute. This has been known to cause issues for some, including messing up thesignalr/hubs.js
file. – Corey$.connection
is defined and has the hub member defined as well. – Corey