2016-02-26 25 views
2

我正在學習從鏈接Asp.Net Signal MVC4旁邊實現SignalR的基本知識。就像教程建議我已經實現了一個演示應用程序,但我無法解決以下錯誤。SignalR錯誤:signalR(...)。starting(...)。發送不是函數

Uncaught TypeError: signalR(...).starting(...).sending is not a function

這是我到目前爲止嘗試過的。

先決條件:

  1. Microsoft.AspNet.SignalR
  2. WebAPIDoodle.SignalR

樞紐

namespace SignalRChat.Hubs 
{   
    public class ChatHub : Hub 
    { 
     public void Send(string name, string message) 
     { 
      Clients.All.addNewMessageToPage(name, message); 
     } 
    } 
} 

Ø贏啓動

[assembly: OwinStartup(typeof(SignalRChat.Startup))] 

namespace SignalRChat 
{ 
    public class Startup 
    { 
     public void Configuration(IAppBuilder app) 
     { 
      app.MapSignalR(); 
     } 
    } 
} 

控制器

public ActionResult Chat() 
{ 
    return View(); 
} 

視圖(聊天)

@{ 
    ViewBag.Title = "Chat"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<h2>Chat</h2> 
<div class="container"> 
    <input type="text" id="message" /> 
    <input type="button" id="sendmessage" value="Send" /> 
    <input type="hidden" id="displayname" /> 
    <ul id="discussion"></ul> 
</div> 
@section scripts { 
    <!--Script references. --> 
    <!--The jQuery library is required and is referenced by default in _Layout.cshtml. --> 
    <!--Reference the SignalR library. --> 
    @*<script src="~/Scripts/jquery.signalR-2.1.0.min.js"></script>*@ 
    <script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.0.0.min.js"></script> 
    <!--Reference the autogenerated SignalR hub script. --> 
    <script src="~/signalr/hubs"></script> 
    <!--SignalR script to update the chat page and send messages.--> 
    <script type="text/javascript"> 
     $(function() { 

      var connection = $.connection('/echo'); 
      console.log(connection); 
      // Reference the auto-generated proxy for the hub. 
      var chat = $.connection.chatHub; 
      // Create a function that the hub can call back to display messages. 
      chat.client.addNewMessageToPage = function (name, message) { 
       // Add the message to the page. 
       $('#discussion').append('<li><strong>' + htmlEncode(name) 
        + '</strong>: ' + htmlEncode(message) + '</li>'); 
      }; 
      // Get the user name and store it to prepend to messages. 
      $('#displayname').val(prompt('Enter your name:', '')); 
      // Set initial focus to message input box. 
      $('#message').focus(); 
      // Start the connection. 
      $.connection.hub.start().done(function() { 
       $('#sendmessage').click(function() { 
        // Call the Send method on the hub. 
        chat.server.send($('#displayname').val(), $('#message').val()); 
        // Clear text box and reset focus for next comment. 
        $('#message').val('').focus(); 
       }); 
      }); 
     }); 
     // This optional function html-encodes messages for display in the page. 
     function htmlEncode(value) { 
      var encodedValue = $('<div />').text(value).html(); 
      return encodedValue; 
     } 
    </script> 
} 

我不能夠解決以下錯誤。有什麼我在這裏失蹤,因爲我已經安裝了所有必需的文件,並使用最新的JQuery。我嘗試使用較低版本的signalR,但仍然存在相同的問題。

這裏是開發人員控制檯的錯誤列表的快照。

enter image description here

錯誤

enter image description here

回答

1

的來源我終於整理出異常我已經在我的問題提到的。其實我已經不必要地安裝了WebAPIDoodle.SignalR dll。我已經拋棄了這個項目,並在新項目安裝完成後立即開始使用新項目。我去了打包控制檯管理器,然後逐一更新了下面的dll。

  1. Microsoft.AspNet.SignalR
  2. Microsoft.Owin
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Host.SystemWeb

休息過程是一樣的教程創建建議一個owin啓動班和一個班級班。這樣做的應用程序完美工作,就像教程中提到的一樣。我注意到的兩個項目signalr autogenereted javascript是不同的我猜這是因爲以前我已經不必要地安裝了WebAPIDoodle.SignalR DLL給了我不同的JavaScript。