5
Ho classe hub:SignalR javascript richiamata non funziona
public class ChatHub : Hub
{
// Send message
public void Send(string message)
{
Clients.addMessage(DateTime.Now.ToString("HH:mm:ss") + " " + message);
}
}
e JavaScript:
// Proxy created on the fly
var chat = $.connection.chatHub;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function(message) {
alert("message:" + message);
$('#chat').append('<div>' + message + '</div>');
};
$("#sendButton").click(function() {
// Call the chat method on the server
chat.send($('#message').val())
.done(function() {
console.log('Success!')
})
.fail(function (e) {
console.warn(e);
})
});
// Start the connection
$.connection.hub.start();
Tutti conection vanno bene:
Se uso punto di interruzione in qui Clienti. addMessage (DateTime.Now.ToString ("HH: mm: ss") + "" + messaggio); tutto va bene.
Ma non ricevo il callback sulla funzione javascript. avviso ("messaggio:" + messaggio); non esegue mai
Il codice sembra buono. Dove lo stai eseguendo? IIS? VS? – davidfowl
@dfowler su ISS 7.5 –
Il codice javascript è riportato sopra nell'evento pronto o simile? – escouser