Note that there are some explanatory texts on larger screens.

plurals
  1. POTypeError: chat.send is not a function
    text
    copied!<p>So, i am pretty new to SignalR(just started playing with it this week) but havent got it to work yet. Im trying to get a simple chat working in MVC 4 but ive been stuck for some time now, this is what i have so far, any hints or tips would be useful!</p> <p>The error i currently get with firebug is this: "TypeError: chat.send is not a function"</p> <p>Startup.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Owin; namespace SignalRWebChatVer2 { public class Startup { public void Configuration(IAppBuilder app) { var config = new HubConfiguration { EnableCrossDomain = true }; app.MapHubs(config); } } } </code></pre> <p>ChatHub.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace SignalRWebChatVer2 { [HubName("ChatHub")] public class ChatHub : Hub { public void Send(string messages) { Clients.All.addMessage(messages); } } } </code></pre> <p>Chat.cshtml</p> <pre><code>@{ ViewBag.Title = "Chat"; Layout = "~/Views/Shared/_Layout.cshtml"; } &lt;h2&gt;Chat&lt;/h2&gt; &lt;div&gt; &lt;input type="text" id="msg"/&gt; &lt;input type="button" id="broadcast" value="Send"/&gt; &lt;ul id="messages"&gt;&lt;/ul&gt; &lt;/div&gt; </code></pre> <p>_Layout.csthml</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;@ViewBag.Title - My ASP.NET MVC Application&lt;/title&gt; &lt;link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /&gt; &lt;meta name="viewport" content="width=device-width" /&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.signalR-2.0.0-beta2.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/signalr/hubs")" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; $(function() { var chat = $.connection.chatHub; //$.connection.hub.start(); chat.client.addMessage = function(messages) { $("#messages").append('&lt;li&gt;' + messages + '&lt;/li&gt;'); }; $.connection.hub.start().done(function() { $("#broadcast").click(function() { //var message = $('#msg').val(); chat.send($('#msg').val()); //chat.server.send(message); }); }); }); &lt;/script&gt; &lt;header&gt; &lt;div class="content-wrapper"&gt; &lt;div class="float-left"&gt; &lt;p class="site-title"&gt;@Html.ActionLink("your logo here", "Index", "Home")&lt;/p&gt; &lt;/div&gt; &lt;div class="float-right"&gt; &lt;section id="login"&gt; @Html.Partial("_LoginPartial") &lt;/section&gt; &lt;nav&gt; &lt;ul id="menu"&gt; &lt;li&gt;@Html.ActionLink("Home", "Index", "Home")&lt;/li&gt; &lt;li&gt;@Html.ActionLink("About", "About", "Home")&lt;/li&gt; &lt;li&gt;@Html.ActionLink("Contact", "Contact", "Home")&lt;/li&gt; &lt;li&gt;@Html.ActionLink("Chat", "Chat", "Home")&lt;/li&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/div&gt; &lt;/div&gt; &lt;/header&gt; &lt;div id="body"&gt; @RenderSection("featured", required: false) &lt;section class="content-wrapper main-content clear-fix"&gt; @RenderBody() &lt;/section&gt; &lt;/div&gt; &lt;footer&gt; &lt;div class="content-wrapper"&gt; &lt;div class="float-left"&gt; &lt;p&gt;&amp;copy; @DateTime.Now.Year - My ASP.NET MVC Application&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/footer&gt; @*@RenderSection("scripts", required: false)*@ &lt;/body&gt; </code></pre> <p></p> <p>Is there anything more you need to see? If so just hit me up and i will get back ASAP. </p> <p>Anyway, thanks in advance. Best regards, </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload