im getting a prblem when i want to send data o start a sub from hub when the page is loading. ill put this sample code because is short
this is my chat.vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports SignalR.Hubs
Public Class Chat
Inherits Hub
Public Sub Send(message As String)
' Call the addMessage method on all clients
Clients.addMessage(message)
End Sub
End Class
and this is my default.aspx
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-0.5.3.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val());
});
// Start the connection
$.connection.hub.start();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="position: absolute; left: 0; top: 0; height: 100%; width: 100%">
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
</div>
</form>
</body>
i dont want to press the button, i want he doit all by itself when loads the page
when i put it like this
<script language="javascript" type="text/javascript">
$(document).ready(function () {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
chat.send('Hello World');
// Start the connection
$.connection.hub.start();
});
</script>
i got an connection problem
i get this error “SignalR: Connection must be started before data can be sent. Call .start() before .send()”;
You must call start before you do send.
So:
SHOULD BE:
Hope this helps!