Below code with ASP.Net SignalR Hub technology. These codes are not working as expected. When I am clicking on Hello Butting it is working fine but when I am clicking on UserList nothing is happening. I have placed an alert and found server method is invoking but after that nothing happening.
JavaScript
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
chat.client.OnlineFriends = function (userLists) {
alert(userLists);
};
chat.client.Hello = function (message) {
alert(message);
};
// Start the connection.
$.connection.hub.start().done(function () {
$('#btnGetUser').click(function () {
chat.server.Friends();
});
$('#btnHello').click(function () {
chat.server.test("message to server from client");
//
});
});
});
and C# code
public class ChatHub : Hub
{
public void Test(string str)
{
Clients.Caller.Hello(str + " | Message received at server reply from server.");
}
public void Friends()
{
Clients.Caller.OnlineFriends("myid");
}
}
and HTML
<div>
<input type="button" id="btnHello" value="Hello" />
<input type="button" id="btnGetUser" value="UserList" />
</div>
Please help to find out what is the problem.
Below code with ASP.Net SignalR Hub technology. These codes are not working as expected. When I am clicking on Hello Butting it is working fine but when I am clicking on UserList nothing is happening. I have placed an alert and found server method is invoking but after that nothing happening.
JavaScript
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
chat.client.OnlineFriends = function (userLists) {
alert(userLists);
};
chat.client.Hello = function (message) {
alert(message);
};
// Start the connection.
$.connection.hub.start().done(function () {
$('#btnGetUser').click(function () {
chat.server.Friends();
});
$('#btnHello').click(function () {
chat.server.test("message to server from client");
//
});
});
});
and C# code
public class ChatHub : Hub
{
public void Test(string str)
{
Clients.Caller.Hello(str + " | Message received at server reply from server.");
}
public void Friends()
{
Clients.Caller.OnlineFriends("myid");
}
}
and HTML
<div>
<input type="button" id="btnHello" value="Hello" />
<input type="button" id="btnGetUser" value="UserList" />
</div>
Please help to find out what is the problem.
Share Improve this question asked Dec 9, 2013 at 13:09 Suman BiswasSuman Biswas 1693 gold badges7 silver badges20 bronze badges3 Answers
Reset to default 3Could you try to change the line
chat.server.Friends();
to:
chat.server.friends();
I guess the generated javascript has the java convention on naming. That is the only difference I can see from those two methods.
As mentioned by @scheien you need to call the method using a lower case first letter. Optionally, you can specify the hub method name as detailed here.
[HubMethodName("MyNewMethodName")]
public void Friends()
and then call server functions using that new name
chat.server.MyNewMethodName();
chat.client.onlineFriends = function (userLists) {
alert(userLists);
};
but...... userLists
does not exist on the hub:
Clients.CalleronlineFriends("myid");
This was one thing, and another thing that cought my eye was that the javascript part doesn't start with a capital letter
So you must also change Friends
, Hello
, OnlineFriends
into friends
, hello
onlineFriends