Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<


default.aspx
--------------
when i run the code vs2010 .net framework 4.0
default web page display  but the append message is not getting when i click send button
whats wrong in this coding

html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SignalR</title>
    <script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripts/jquery.signalR-0.5.3.min.js"> </script>
    <script src="/signalr/hubs" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            var chat = $.connection.chat;
            alert("connection");

            chat.client.addMessage = function (message) {
            $('#messages').append($('<li>'+message+'</li>'))};

       
            $("#broadcast").click(function () {

                chat.server.send($('#msg').val());
                alert("broadcast");
            });
            $.connection.hub.start();


        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h2>SignalR</h2>
<input type="text" id="msg"/>
<input type="button" id="broadcast" value="Send" />
        <br />
        <br />
<ul id="messages"></ul>
    </div>
    </form>
</body>
</html>


C#
chat.cs
-------
<pre lang="cs">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.AspNet.SignalR;
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;

/// &lt;summary&gt;
/// Summary description for chat
/// &lt;/summary&gt;

public class chat:Hub

{

    public void send (string message)
    {

        Clients.All.addMessgae(message);

    }</pre>


i corrected it answer 1 as val('') to val() again i getting same errors as follows

"JavaScript runtime error: Unable to get property 'client' of undefined or null reference"

"JavaScript runtime error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/js'></script>."

"{throw new Error("SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. <script src='/signalr/js'></script>.");"

suggest me the solution or example
Posted
Updated 3-Sep-14 2:13am
v3

1 solution

Hi,

You are sending a blank message so your are getting a blank message.

// Your Code
$('#msg').val('')

Should be

$('#msg').val()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900