[英]Uncaught TypeError: undefined is not a function
我正在按照此站點上的示例嘗試並實施實時網絡聊天應用程序。 我對javascript到jQuery非常陌生,所以我想我只是復制示例並在添加過程中學習。
這是我正在使用的代碼:
@{
ViewBag.Title = "OnlineUsers";
}
<html>
<head>
<title>Online Users</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.4/leaflet.js"></script>
</head>
<body>
<div id="wrapper">
<div id="upperPanel">
<div>
<ul id="messages" itemid="@HttpContext.Current.User.Identity.Name">
</ul>
</div>
<div id="friends">
</div>
</div>
<div id="bottomPanel">
<textarea rows="2" cols="100" id="chatMessage"></textarea>
<input id="chatSubmitMessage" type="submit" value="Send" style="margin-left: 10px;" /><br />
</div>
</div>
<script type="text/javascript">
$(function () {
var pusher = new window.Pusher('0b7eeff567653e170094');
var channel = pusher.subscribe('chat_channel');
channel.bind('message_received', function (data) {
$("#messages").
append('<li>' + data.user + ' ' + data.message + ' ' + data.timestamp + '</li>');
});
$('#chatSubmitMessage').bind('click', function () {
$.post("/", {
chatMessage: $('#chatMessage').val(),
username: $('#messages').attr('itemid')
});
});
});
</script>
</div>
</body>
</html>
此代碼在Chrome調試器中給了我以下錯誤:
Uncaught TypeError: undefined is not a function
(anonymous function)
fire jquery-1.8.2.js:974
self.add jquery-1.8.2.js:1018
jQuery.fn.jQuery.ready jquery-1.8.2.js:246
jQuery.fn.jQuery.init jquery-1.8.2.js:174
jQuery jquery-1.8.2.js:44
(anonymous function)
(anonymous function) jquery-1.8.2.js:564
jQuery.extend.globalEval jquery-1.8.2.js:565
(anonymous function) jquery-1.8.2.js:6006
jQuery.extend.each jquery-1.8.2.js:611
jQuery.fn.extend.domManip jquery-1.8.2.js:5991
jQuery.fn.extend.append jquery-1.8.2.js:5764
jQuery.fn.(anonymous function) jquery-1.8.2.js:6186
$.ajax.success jquery.mobile-1.2.0.js:3685
fire jquery-1.8.2.js:974
self.fireWith jquery-1.8.2.js:1082
done jquery-1.8.2.js:7788
callback
我假設錯誤與未命名函數有關,任何幫助將不勝感激。
您不是在加載jquery,而是嘗試使用它。 將此添加到您的頭上
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
您是否已包含Pusher代碼? 通過打開Web檢查器並嘗試查看window.Pusher是否確實未定義來確保。 如果未定義,則將Pusher及其依賴項包括到文件的開頭 。 讓我知道這是否是您的問題。 很難說明問題中給出了什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.