0
Follows the code:
var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');
contosoChatHubProxy.on('addContosoChatMessageToPage', function(name, message) {
console.log(name + ' ' + message);
});
connection.start().done(function() {
// Wire up Send button to call NewContosoChatMessage on the server.
$('#newContosoChatMessage').click(function () { // <----------AQUI
contosoChatHubProxy.invoke('newContosoChatMessage', $('#displayname').val(), $('#message').val());
$('#message').val('').focus();
});
});
I just don’t want the job click
to run this line below:
contosoChatHubProxy.invoke('newContosoChatMessage', $('#displayname').val(), $('#message').val());
There is another way to run the above line without using the click function ?
Documento Signalr: https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client
UPDATE:
$(function () {
myFunction();
});
function myFunction() {
var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');
contosoChatHubProxy.on('addContosoChatMessageToPage', function (name, message) {
console.log(name + ' ' + message);
});
connection.start().done(function () {
$('#newContosoChatMessage').click(function () { // <----------AQUI
contosoChatHubProxy.invoke('newContosoChatMessage', $('#displayname').val(), $('#message').val());
$('#message').val('').focus();
});
});
}
If it’s not in the
click
, at what point? There are several ways– BrTkCa
Expensive anything !!! , minus the click function. It can be a simple function of
myFunction
. I’ve tried everything, it doesn’t work.– Matheus Miranda