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

  
  <input type="text" id="msg" />
  <a id="broadcast" href="#">Send message</a>

<p>Messages : </p>
<ul id="messages">  </ul>


<script type="text/javascript">
    $(function () {
        
        // Proxy created on the fly
        var chat = $.connection.chat;
        $.connection.hub.logging = true;
        
        // Declare a function on the chat hub so the server can invoke it
        chat.client.addMessage = function (message, from) {
            $('#messages').append('<li>' + message  + " from " + from + '</li>');
        };

        chat.client.onConsoleMessage = function (message) {
            $('#messages').append('<li> From the console application : ' + message + '</li>');
        };

        $("#broadcast").click(function () {
            // Call the chat method on the server
            chat.server.send($('#msg').val())
             .done(function () {
                 console.log('Success!');
             })
             .fail(function (e) {
                 console.warn(e);
             });
        });

        $("#broadcast").hide();

        // Start the connection
        $.connection.hub.start({transport: 'auto'},function () {
            $("#broadcast").show();
            console.log("Success");
        });
    });
  </script>

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

  
  <input type="text" id="msg" />
  <a id="broadcast" href="#">Send message</a>

<p>Messages : </p>
<ul id="messages">  </ul>


<script type="text/javascript">
    $(function () {
        
        // Proxy created on the fly
        var chat = $.connection.chat;
        $.connection.hub.logging = true;
        
        // Declare a function on the chat hub so the server can invoke it
        chat.client.addMessage = function (message, from) {
            $('#messages').prepend('<li>' + message  + " from " + from + '</li>');
        };

        chat.client.onConsoleMessage = function (message) {
            $('#messages').prepend('<li> From the console application : ' + message + '</li>');
        };

        $("#broadcast").click(function () {
            // Call the chat method on the server
            chat.server.send($('#msg').val())
             .done(function () {
                 console.log('Success!');
             })
             .fail(function (e) {
                 console.warn(e);
             });
        });

        $("#broadcast").hide();

        // Start the connection
        $.connection.hub.start({transport: 'auto'},function () {
            $("#broadcast").show();
            console.log("Success");
        });
    });
  </script>

Prepend debug messages in the web chat example.
Prepend debug messages in the web chat example.
