Danny Ellis Jr.
Danny Ellis Jr.

Reputation: 1706

SignalR throwing JavaScript Error

I'm new to signalr. I've started an MVC 4.0 application, out of the box, and wired up my signalr JavaScript on the Index View. When I click either the Register or Login buttons, signalr throws a JavaScript error.

Unhandled exception at line 11, column 10700 in http://localhost:49172/Scripts/jquery.signalR-   0.5.1.min.js

0x800a138f - Microsoft JScript runtime error: Unable to set value of the property 'src': object is null or undefined

Any suggestions appreciated.

EDIT:

This is the extent of my code:

$(function () {    
    var blasht = $.connection.blashtHub;    
    blasht.addMessage = function (message) {
        $('#messages').append('<li>' + message + '');
    };     

    $("#blashtIt").click(function () {
        var control = $('#blashtText');
        var control2 = $('#hiddenUserId');
        // Call the chat method on the server  
        blasht.send(control2.val(), control.val());
        control.val('');
    });

    blasht.updateTopTen = function (message) {
        //add code to update the top user's list
    };

    // Start the connection   
    $.connection.hub.start();
});

As suggested I dropped the min and here is where it is crashing, on the frame.sc = src; line.

reconnect: function (connection) {
    var that = this;
    window.setTimeout(function () {
    var frame = connection.frame,
    src = transportLogic.getUrl(connection, that.name, true) + "&frameId=" + connection.frameId;
               connection.log("Upating iframe src to '" + src + "'.");
               frame.src = src;
            }, connection.reconnectDelay);
        },

SignalR, not me, is invoking this reconnect function. Obviously, that is how it maintains a connection with the server.

Upvotes: 1

Views: 2800

Answers (2)

Andres
Andres

Reputation: 687

The is a bug in the current version of SignalR for the "Forever-Frame" implementation, which is the one that IE9 uses: https://github.com/SignalR/SignalR/issues/446

A workaround is to force SignalR not to use Forever-Frame transport (https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client). So change

$.connection.hub.start();

to

$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });

Upvotes: 9

T.J. Crowder
T.J. Crowder

Reputation: 1075447

From the error message, and without your having shown any code, I'd have to guess that you have code that looks like this:

foo.src = someValue;

...where foo is null or undefined. Which begs the question of why is foo null or undefined, but without more context, it's impossible to say. Stepping through with the IE8+ "F12 Developer Tools" may help you pinpoint it.


(Update after code was posted)

I'm guessing that the line causing the error is frame.src = src;. Reformatting that code with consistent indentation:

reconnect: function (connection) {
    var that = this;
    window.setTimeout(function () {
        var frame = connection.frame,
            src = transportLogic.getUrl(connection, that.name, true) + "&frameId=" + connection.frameId;
        connection.log("Upating iframe src to '" + src + "'.");
        frame.src = src;  // <=== Presumably this is the line failing
    }, connection.reconnectDelay);
},

It would appear that as of the time the delayed function is called, connection.frame is null or undefined. So you'll need to find out why that is. The first thing I'd do is check whether connection.frame is null or undefined when reconnect is called, or if it's only later when the delayed function runs (e.g., has something cleared it in the meantime, and if so, why).

Upvotes: 0

Related Questions