SignalR:未捕获类型错误:无法读取属性“聊天”的未定义 [英] SignalR: Uncaught TypeError: Cannot read property 'chat' of undefined

查看:580
本文介绍了SignalR:未捕获类型错误:无法读取属性“聊天”的未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 2013的WebForms模板与引导。而且我有

VS 2013 WebForms template with bootstrap. And I've got

<script src="/Scripts/jquery-2.0.3.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.signalR-2.0.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/signalr/hubs"></script>

(用来尝试 signalr /集线器 ResolveClientUrl(〜/ signalr /中心)等。 。)

<script type="text/javascript">
    $(function () {
        // Proxy created on the fly connection
        var chat = $.connection.chat;

我曾经尝试各种变体以及用于搜索了很多关于这个麻烦,但仍然是现在找不到解决办法。当我检查加载页面的来源和点击 signalr /集线器我可以看到加载代理那里,我还可以看到聊天那里。

I used to try various variants and used to search a lot about this trouble but still can't find solution for now. When I check loaded page sources and click on signalr/hubs I can see proxies loaded there and I also can see chat there.

但我仍然收到未捕获类型错误:无法读取属性的聊天的未定义


  • 如何调试呢?

  • 为什么会发生这种事?

推荐答案

如果 $。连接没有设置,那么SignalR初始化code在jquery.signalR - * min.js不运行或预期至少没有完成。一个可能的原因可能有包含的页面(在VS模板添加一个参考,因此,如果你加入另一个手动,这可能是问题)上的多个版本的jQuery。在这种情况下,窗口。$ 实例,SignalR把自己定中简单地通过第二jQuery的初始化脚本设置窗口取代。$ 一次。
如果不是它,你应该尝试用unminified版本替换缩小的SignalR脚本。然后,在code的开始(例如,在第一行以匿名函数使用严格)设置断点,在这样一行 $。连接= $ .signalR = signalR ; 或同级(接近尾声)

If $.connection is not set, then the SignalR initialization code in jquery.signalR-*.min.js is not running or at least not finishing as expected. A possible cause might be having multiple jQuery versions included on the page (the VS templates add a reference, so if you added another one manually, this might be the problem). In that case, the window.$ instance which SignalR set itself up in is simply being replaced by the second jQuery initialization script which sets window.$ again. If that is not it, you should try replacing the minified SignalR script with the unminified version. Then set breakpoints at the beginning of the code (e.g. on the first line with "use strict" within the anonymous function), and at a line that says $.connection = $.signalR = signalR; or similar (towards the end).

如果没有被击中,那么脚本以某种方式不是在所有发现的。如果第一个被击中,但第二个是没有,有一些其它的问题 - 你可以向后跟踪它从那里。这可能是与如何创建集线器或其他配置问题一个问题。

If neither are hit, then the script is somehow not found at all. If the first one is hit, but the second one isn't, there is some other problem - you could trace it backwards from there. It might be a problem with how you create the Hub, or another configuration problem.

这篇关于SignalR:未捕获类型错误:无法读取属性“聊天”的未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆