我有一个用过的 SignalR 来创建聊天。它工作得很好但是当我在母版页中使用它时会出现以下错误
Uncaught TypeError: Cannot read property 'chat' of undefined
(anonymous function)
fire
self.fireWith
jQuery.extend.ready
DOMContentLoaded
错误在于:
<script type="text/javascript">
$(function () {
var chat = $.connection.chat;
**Uncaught TypeError: Cannot read property 'chat' of undefined**
$.connection.hub.start({ transport: 'auto' }, function () {
//alert('connected');
$('#MainContent_connected').text('Connected to chat room');
});
$("#broadcast").click(function () {
chat.send($("#MainContent_userName").text() + $("#msg").val());
$("#msg").val('')
});
/* Declaring the Function on the chat hub in order for the server to
be able to invoke it. */
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
});
</script>
关于如何解决这个问题的任何想法?