未捕获类型错误:未定义不是一个函数 [英] Uncaught TypeError: undefined is not a function

查看:305
本文介绍了未捕获类型错误:未定义不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从本网站尝试和实现实时网络聊天应用程序。我非常新的JavaScript jQuery的,所以我想我刚才复制的榜样,学习,因为我去添加一些东西。

I am following the example from this site to try and implement a live web chat application. I am very new to javascript to jquery, so I thought I'd just copy the example and learn as I go and add things.

这是code,我现在用:

This is the code that I am using:

@{
    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>

这code给我下面的错误在Chrome调试器:

This code gives me the following error in the Chrome debugger:

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

我假设的错误是与功能是无名,任何帮助将大大AP preciated。

I'm assuming the error has something to do with the function being unnamed, any help will be greatly appreciated.

推荐答案

您不加载的jQuery,但尝试使用它。添加到您的头上

You are not loading jquery, but trying to use it. Add this to your head

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

这篇关于未捕获类型错误:未定义不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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