admin管理员组文章数量:1244318
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('/');
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?
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/');
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?
Share Improve this question asked Jul 3, 2013 at 10:15 YoungjaeYoungjae 25.1k19 gold badges117 silver badges203 bronze badges1 Answer
Reset to default 10Read tutorial carefully and it works now.
$(function () {
// Declare a proxy to reference the hub.
var connection = $.hubConnection('http://www.website/');
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'); });;
});
本文标签: javascriptSignalR invoke method connection must be started before data can be sentStack Overflow
版权声明:本文标题:javascript - SignalR invoke method: connection must be started before data can be sent - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740141733a2231021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论