3
votes

I am trying the SignalR intro sample from here: http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-getting-started-with-signalr-20

Following the sample, I got the error below after pressing F5:

Unhandled exception at line 17, column 5 in http://myServer.com:12269/signalr/hubs

0x800a138f - JavaScript runtime error: Unable to get property 'signalR' of undefined or null reference

I am new to SignalR, not quite sure where to start. Any insight?

A screenshot of the error. It's part of the generated hubs script.

enter image description here

The source code on the index.html:

<!DOCTYPE html>
<html>
<head>
    <title>SignalR Simple Chat</title>
    <style type="text/css">
        .container {
            background-color: #99CCFF;
            border: thick solid #808080;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <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>
    <!--Script references. -->
    <!--Reference the jQuery library. -->
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="signalr/hubs"></script>
    <!--Add script to update the page and send messages.-->
    <script type="text/javascript">
        $(function () {
            // Declare a proxy to reference the hub.
            var chat = $.connection.chatHub;
            // Create a function that the hub can call to broadcast messages.
            chat.client.broadcastMessage = function (name, message) {
                // Html encode display name and message.
                var encodedName = $('<div />').text(name).html();
                var encodedMsg = $('<div />').text(message).html();
                // Add the message to the page.
                $('#discussion').append('<li><strong>' + encodedName
                    + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</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();
                });
            });
        });
    </script>
</body>
</html>
4
You get this error in your browser?Daniel
@Daniel Yes, I am using IE 10.smwikipedia
Do you load the good version of JQuery before loading the hub?Daniel
Can you share the code where you load JQuery and where you define you connect the client to the hub?Daniel
Just to be sure. Do you have the JQuery script file "jquery-1.6.4.min.js" in the script folder?Daniel

4 Answers

4
votes

You have to reference the appropriate version of JQuery that you have in your Scripts folder.

2
votes

I face the same issue while working on http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr

really the issue is the copied HTML code from one of the instructions. the HTML refers to an older version of Jquery and jquery singnal R

<script src="Scripts/jquery-1.6.4.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>

update these values as per the current automatically loaded script versions as shown below

enter image description here

1
votes

jQuery ($) is not defined, so :

  • it might not be loaded at all
  • it might be loaded after the signalIR file
  • you might be using noConflict
1
votes

The error has to do with jQuery, not SignalR.

Notice the error message says Unable to get property 'signalR' of undefined or null reference. How can we get signalR from an undefined or null object.

To fix, make sure you're attaching jQuery to the page properly.

Again: This has nothing to do with SignalR being naughty, but just a case of the missing jQuery library.


To test if jQuery is actually loaded, run this in your console:

console.log($);

You should get the standard jQuery output. If that doesn't work, try this. If this works, it means you're having an issue with conflicting variables.

console.log(jQuery);