2016-02-26 64 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。