Reputation: 5402
I am using SignalR in an ASP.Net Web Application project and am having issues. My goal is to make any changes in the administrative side of the site cause some GridViews to refresh. I was planning on doing this by sending the signal for some javascript to be run, thereby refreshing the update panels containing the GridViews.
The issue right now is that I cannot get any of the code my hub is trying to call to execute in the client. I am receiving the following error in FireBug from the jquery.SignalR.js file, but I'm not sure how to proceed to fix it:
Firefox can't establish a connection to the server at ws://localhost:40068/signalr?data=[]&transport=webSockets&clientId=92e4f7b9-0118-4fd9-bb55-5f22338d6162.
(function(n,t){"use strict";if(typeof ...on=n.signalR=i})(window.jQuery,window)
After it throws this error it still looks like it is setting up the connection, but none of the javascript being sent through the hub is executed
I have set up the following hub in my site:
namespace testProject
{
public class statusChanges : Hub
{
public void ServerChange()
{
Clients.serverChange();
}
}
}
I have the following code in my button click event in the admin section. Debugging shows that this code is being run by the server:
var clients = Hub.GetClients<statusChanges>();
clients.serverChange();
Finally I have this code in my page trying to just launch an alert when it receieves the signal to confirm it is working.
<script type="text/javascript">
$(function () {
var statusChange = $.connection.statusChanges;
statusChange.serverChange = function () {
alert(8);
};
$.connection.hub.start();
});
</script>
Does any one have any ideas why this would not run or what the FireBug error means?
Upvotes: 2
Views: 4136
Reputation: 38834
The error in firebug is expected. It's the websocket connection failing, don't worry about it as SignalR will fallback to longpolling. You have a method on the server side with the same name as a client side event. That doesn't work.
You want something like this:
public Administration : Hub {
}
Event handler:
var clients = Hub.GetClients<Administration>();
clients.serverChange();
Javascript:
<script type="text/javascript">
$(function () {
var administration= $.connection.administration;
administration.serverChange = function () {
alert(8);
};
$.connection.hub.start();
});
</script>
Upvotes: 5