0

我很难让信号器与 requirejs 一起工作。这是我的代码,但出现以下错误:

_Uncaught Error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/hubs'></script>._

代码:

<script src="~/Scripts/jquery.signalR-1.0.0-rc2.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">

// requirejs configuration setup
requirejs.config({
        baseUrl: '@string.Format("{0}://{1}{2}Scripts/modules", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))', // this might need to change as it depends on the number of / in the url...?
        paths: {
                'jquery': '../jquery-1.9.0',
                'bootstrap': '../bootstrap',
                'knockout': '../knockout-2.2.1',
                'noext': '../noext',
                'sigr': '../jquery.signalR-1.0.0-rc2'
        },
        shim: {
                "sigr": {
                        deps: ['jquery']
                },
                "noext!signalr/hubs": {
                        deps: ['sigr']
                }
        }
});

有没有人对我为什么或如何让它发挥作用有任何想法?

4

1 回答 1

1

我能够使用requirejs ..我按照http://requirejs.org/docs/jquery.html上的教程了解如何插入jquery并添加信号参考以使其工作

require(["jquery", "jquery.alpha", "jquery.beta","jquery.signalr-1.0.0-rc2","/signalr/hubs"], 
    function($) {
    }
);

我认为您必须修改配置才能执行以下任一选项1:

paths: {
    'jquery': '../jquery-1.9.0',
    'bootstrap': '../bootstrap',
    'knockout': '../knockout-2.2.1',
    'noext': '../noext',
    'sigr': '../jquery.signalR-1.0.0-rc2'
    'hubs': '/signalr/hubs'
},

选项2:

shim: {
    "sigr": {
        deps: ['jquery']
    },
    "noext!**/**signalr/hubs": {
        deps: ['sigr']
    }
}
于 2013-02-09T01:54:07.140 回答