I will try to send data to the server using SignalR 2. But I get this error:
Uncaught TypeError: Cannot read property "meldingenHub" 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 necessary file:
<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 an error for 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/Toevoegen?apiKey=@Model.ApiKey",
type: "PUT",
data: json,
success: function (returnData) {
if (returnData.Oke == false) {
toonError(returnData)
}
else {
plaatsKleuren(returnData);
medlingenHub.server.meld(data.ID, data.Punten);
}
}
});
});: , .
Startup.Auth.cs:
public void ConfigureAuth(IAppBuilder app)
{
app.MapSignalR();
}
asp.net. - ?