简体   繁体   English

SignalR抛出JavaScript错误

[英]SignalR throwing JavaScript Error

I'm new to signalr. 我是Signalr的新手。 I've started an MVC 4.0 application, out of the box, and wired up my signalr JavaScript on the Index View. 我已经开箱即用地启动了MVC 4.0应用程序,并在Index View上连接了我的Signalr JavaScript。 When I click either the Register or Login buttons, signalr throws a JavaScript error. 当我单击“注册”或“登录”按钮时,signaler会引发JavaScript错误。

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; 如建议的那样,我在框架上放下了min,这是崩溃的地方。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. SignalR(不是我)正在调用此重新连接功能。 Obviously, that is how it maintains a connection with the server. 显然,这就是它与服务器保持连接的方式。

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 这是SignalR当前版本中“ Forever-Frame”实现的错误,这是IE9使用的错误: 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). 一种解决方法是强制SignalR不要使用永久帧传输(https://github.com/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 . ...其中foonullundefined Which begs the question of why is foo null or undefined , but without more context, it's impossible to say. 这就引出了一个问题, 为什么 foo nullundefined ,但是如果没有更多上下文,就很难说了。 Stepping through with the IE8+ "F12 Developer Tools" may help you pinpoint it. 逐步使用IE8 +“ F12开发人员工具”可能会帮助您确定它。


(Update after code was posted) (发布代码后更新)

I'm guessing that the line causing the error is frame.src = src; 我猜测导致错误的行是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 . 似乎在调用延迟函数时, connection.framenullundefined 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 (eg, has something cleared it in the meantime, and if so, why). 我要做的第一件事是检查在调用reconnectconnection.frame是否为nullundefined ,或者是否只有在延迟函数运行时才稍后(例如,在此期间清除了它,如果是,则清除了原因)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM