私はハブクラスを持っています:
public class ChatHub : Hub
{
// Send message
public void Send(string message)
{
Clients.addMessage(DateTime.Now.ToString("HH:mm:ss") + " " + message);
}
}
そして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();
すべての接続は問題ありません:
ここでブレークポイントを使用する場合Clients.addMessage(DateTime.Now.ToString( "HH:mm:ss")+ "" +メッセージ); すべて順調。
しかし、javascript関数でコールバックを取得しません。 alert( "メッセージ:" +メッセージ); 実行しない