最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SignalR: Uncaught TypeError: Cannot read property 'chat' of undefined - Stack Overflow

programmeradmin0浏览0评论

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>

( used to try signalr/hubs and ResolveClientUrl("~/signalr/hubs") etc... )

and

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

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.

But I still receive Uncaught TypeError: Cannot read property 'chat' of undefined

  • How can I debug it?
  • Why could this happen?

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>

( used to try signalr/hubs and ResolveClientUrl("~/signalr/hubs") etc... )

and

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

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.

But I still receive Uncaught TypeError: Cannot read property 'chat' of undefined

  • How can I debug it?
  • Why could this happen?
Share Improve this question asked Dec 2, 2013 at 9:27 cndcnd 33.8k63 gold badges190 silver badges319 bronze badges 12
  • simply means connection (in $.connection) is undefined. Try other ways to reference this connection object(like window.connection if its global variable) – jsjunkie Commented Dec 2, 2013 at 9:46
  • @jsjunkie I don't know I think it's somewhere in SignalR API – cnd Commented Dec 2, 2013 at 9:55
  • 2 Type javascript:alert($.connection) in you browsers address bar and if doesn't alerts "undefined" then check that you are importing js files before you have written your javascript function. If you get "undefined" then check stackoverflow./questions/16310554/… – jsjunkie Commented Dec 2, 2013 at 10:07
  • @jsjunkie it said undefined – cnd Commented Dec 2, 2013 at 10:11
  • I got one more link to your problem. Hope it helps stackoverflow./questions/11179644/… – jsjunkie Commented Dec 2, 2013 at 10:27
 |  Show 7 more ments

1 Answer 1

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论