Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  162] [ 6]  / answers: 1 / hits: 28044  / 11 Years ago, wed, july 3, 2013, 12:00:00

There are lots of 'connection must be started before data can be sent' issues in here and GitHub, but I hardly find hub related problems.



$(function () {
// Declare a proxy to reference the hub.
var connection = $.hubConnection('http://www.website.net/');
var chat = connection.createHubProxy('MyHub');

// Start the connection.
$.connection.hub.start().done(function () {
console.log('Connect! connection Id=' + $.connection.hub.id);

$('#sendmessage').click(function () {
chat.invoke('method1','0000').done(function () {
console.log ('Invocation of method1 succeeded');
}).fail(function (error) {
console.log('Invocation of method1 failed. Error: ' + error);
});
});
})
.fail(function(){ console.log('Could not Connect!'); });
});


The above code gives to execute a method when user clicks the button.
I can check the method works with my WPF .NET app.



I can get Connection Id successfully, but when I click the button it says 'SignalR invoke method: connection must be started before data can be sent. Call .start() before .send()' error.



What did I wrong?


More From » signalr

 Answers
57

Read tutorial carefully and it works now.



 $(function () {
// Declare a proxy to reference the hub.
var connection = $.hubConnection('http://www.website.net/');
var chat = connection.createHubProxy('MyHub');

connection.start().done(function() {
console.log('Now connected, connection ID=' + connection.id);
// Wire up Send button to call sendmessage on the server.
$('#sendmessage').click(function () {
chat.invoke('method1', '0000');
});
})
.fail(function(){ console.log('Could not connect'); });;
});

[#77232] Tuesday, July 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinah

Total Points: 268
Total Questions: 113
Total Answers: 89

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;