2012-11-04 8 views
1

예를 들어 this site에서 라이브 웹 채팅 응용 프로그램을 구현하려고합니다. 나는 jquery에 javascript를 처음 사용하기 때문에 예제를 복사하고, 내가 가서 추가 할 때 배울 것이라고 생각했다.잡히지 않은 유형 오류 : 정의되지 않은 함수가 아닙니다.

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 

내가 오류를 있으리라 믿고있어 함께 할 수있는 뭔가가 :

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

이 코드는 나에게 크롬 디버거에서 다음과 같은 오류를 제공합니다 :

내가 사용하고있는 코드입니다 기능 이름이없는, 어떤 도움을 크게 주시면 감사하겠습니다.

+0

각 게시물마다 다른 상황에 대한 답변이 있으므로 훈련받은 눈을 가진 사람이 1000 초 이상의 게시물을 탐색하는 것보다 훨씬 빨리 내 오류를 발견 할 수 있다고 생각했습니다. – Matt

답변

6

jquery를로드하지 않고 사용하려고합니다. 머리에 추가하십시오.

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

시도했지만 여전히 같은 오류가 발생합니다. mvc 4 프로젝트에 jquery가 자동으로 포함되어 있지 않습니까? Layout.cshtml 파일에는 @ Scripts.Render ("~/bundles/jquery", "~/bundles/jquerymobile") – Matt

+0

이 포함되어 있습니다. 결국 jQuery를 추가하면 다른 누락 된 종속성이 해결되지 않았습니다 Vinay가 지적한 것처럼) 또한 같은 오류를 반환했습니다. 도움을 주셔서 감사합니다 :) – Matt

2

푸시 코드가 포함되어 있습니까? 웹 속성을 열고 window.Pusher가 실제로 정의되지 않았는지 확인하십시오. 정의되지 않은 경우 include Pusher and its dependencies to the head of your file. 그게 당신 문제인지 알려주세요. 질문에 주어진 내용으로 말하기는 어렵습니다.

+0

당신은 내가 여러 종속성이 포함되지 않은 문제를 찾을 수있었습니다. 예제 솔루션을 다운로드하여 게시 된 예제가 아닌 공유 레이아웃 파일에 포함 시켰음을 확인했습니다. +1 나를 돕기 위해,하지만 목사님이 먼저 대답했습니다. 도와 주셔서 감사합니다 :) – Matt

관련 문제