最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net mvc - SignalR throwing JavaScript Error - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Jun 27, 2012 at 11:12 Danny Ellis Jr. asked Jun 26, 2012 at 23:11 Danny Ellis Jr.Danny Ellis Jr. 1,7083 gold badges25 silver badges46 bronze badges 2
  • 1 You'll have to show your code, and in particular the code that sets the src property as well as the code that gets whatever object you're setting the src property on. – T.J. Crowder Commented Jun 26, 2012 at 23:19
  • This particular bug was fixed, so upgrade SignalR :) – davidfowl Commented Jul 25, 2012 at 20:47
Add a ment  | 

2 Answers 2

Reset to default 9

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

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

$.connection.hub.start();

to

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

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).

发布评论

评论列表(0)

  1. 暂无评论