2013-02-07 81 views
1

我已經嘗試了所有寫在FAQ它幫助我避免我面臨除了無法讀取屬性的「聊天」的不確定

(Uncaught TypeError: Cannot read property 'chat' of undefined)

這裏的所有問題是我的代碼:

[[ 

<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script> 
<script src="~/Scripts/jquery.signalR-1.0.0-rc2.min.js" type="text/javascript"></script> 
<script src="~/signalr/hubs" type="text/javascript"></script> 

<script type="text/javascript"> 
    $(function() { 

     // Proxy created on the fly   
     var chat = $.connection.chat; 

     // Declare a function on the chat hub so the server can invoke it   
     chat.client.addMessage = function (message) { 
      $('#messages').append('<li>' + message + '</li>'); 
     }; 


     // Start the connection 
     $.connection.hub.start().done(function() { 
      $("#broadcast").click(function() { 
       // Call the chat method on the server 
       chat.server.send($('#msg').val()); 
      }); 
     }); 
    }); 
]] 
+4

你有沒有在你的頁面中包含兩次jQuery? – davidfowl

+0

@Ahmed你能否提供更多的細節?它是Javascript嗎? –

+0

我想,如果你想讓人們幫忙,你將不得不張貼一些代碼。 – Gray

回答

0

只爲事實上,當你定義'聊天'時,你是否在.js中使用了[[,]]雙方括號?

+1

這是asp.net MVC4項目使用signalR 那個錯誤發生在我的客戶端代碼 –

+1

根據你的代碼,一切都是正確的。所以錯誤來自別的地方。由於您使用的是MVC,您是否使用而不是

+1

問題解決了,謝謝各位特意給@dfowler 這個問題解決了,當我刪除@Scripts.Render(「〜/ bundles/jquery」) –