2

I am trying to use signalR for the first time however when my hub 'simpleEvent' is always undefined

$(document).ready(function () {

var simple = $.connection.simpleEvent;

....

If I go to localhost/mywebapp/signalR/hubs I get the following error message: "unable to download hubs from localhost. Unable to open this Internet site. The requested site is either unavailable or cannot be found.". However if I try again then hubs in downloaded and it looks like it has the correct hub information, such as

// Create hub signalR instance
$.extend(signalR, {
    simpleEvent: {
        _: {
            hubName: 'MyCorp.Siep.App.Web.UI.SimpleEventHub',
            ignoreMembers: ['init', 'timerExpired', 'namespace', 'ignoreMembers', 'callbacks'],
            connection: function () { return signalR.hub; }
        },

        init: function (callback) {
            return serverCall(this, "Init", $.makeArray(arguments));
        },

        timerExpired: function (state, callback) {
            return serverCall(this, "TimerExpired", $.makeArray(arguments));
        }
    }
});

signalR.hub = signalR("/App.Web.UI/signalr")
    .starting(function () {
        updateClientMembers(signalR);
    })
    .sending(function () {
        var localHubs = [];

        $.each(hubs, function (key) {
            var methods = [];

            $.each(this, function (key) {
                if (key === "obj") {
                    return true;
                }

                methods.push(key);
            });

            localHubs.push({ name: key, methods: methods });
        });

        this.data = window.JSON.stringify(localHubs);
    })
    .received(function (result) {
        var callbackId, cb;
        if (result) {
            if (!result.Id) {
                executeCallback(result.Hub, result.Method, result.Args, result.State);
            } else {
                callbackId = result.Id.toString();
                cb = callbacks[callbackId];
                if (cb) {
                    callbacks[callbackId] = null;
                    delete callbacks[callbackId];
                    cb.callback.call(cb.scope, result);
                }
            }
        }
    });

I have tried the SignalR samples and they work fine, I have read lots of other forum posts regarding this error and most of them appear to be because is incorrect, I am assuming that if I can download the hubs then this is not the issue. What else could be causing this problem?

I am trying to use signalR within: - A Web Appplication - Running within visual studio 2010 deployment server and iis 7 - Intenert Explorer 8 - Windows 2008 server

Any help would be greatly appreciated.

4

2 回答 2

0

检查您的母版页是否放置了正确的脚本引用

<script src="../Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="../Scripts/jquery.signalR.js" type="text/javascript"></script>
<script src="../signalr/hubs" type="text/javascript"></script>
于 2012-08-21T08:28:50.467 回答
0

以下文件很重要(检查正确的顺序):

  1. jQuery JS 文件
  2. SignalR JS 文件
  3. 如果您正在使用生成的集线器,则 HubFile 可选。

这是一个示例:

<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<script src="signalr/hubs"></script>

检查引用的文件是否在目录中(也许您有一个控制台错误,即缺少引用的文件。

如果您正在使用生成的集线器代理,重要的是您没有禁用自动生成集线器文件(路径也必须正确)

var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
hubConfiguration.EnableJavaScriptProxies = false;
app.MapSignalR("/signalr", hubConfiguration);
于 2016-09-28T05:40:17.640 回答