SignalR连接获得警告 - 不推荐在主线程上使用同步XMLHttpRequest

时间:2017-05-03 11:57:15

标签: jquery ajax signalr

我已使用jquery v1.10.2jquery.signalr-2.2.1.min.jsSignalR hub建立联系,但我在Chrome控制台中收到以下警告:

  

jquery-1.10.2.js:8686 [Deprecation]同步XMLHttpRequest上   主线程因其不利影响而被弃用   最终用户的经验。如需更多帮助,请检查   https://xhr.spec.whatwg.org/

完整的控制台日志:

[10:20:22 GMT+0200 ] SignalR: Window unloading, stopping the connection.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Stopping connection.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Closing the Websocket.
:7700/Scripts/jquery-1.10.2.js:8686 

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
send @ :7700/Scripts/jquery-1.10.2.js:8686
ajax @ :7700/Scripts/jquery-1.10.2.js:8150
ajax @ ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
ajaxAbort @ ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
abort @ ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
stop @ ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
(anonymous) @ ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9
dispatch @ :7700/Scripts/jquery-1.10.2.js:5109
elemData.handle @ :7700/Scripts/jquery-1.10.2.js:4780
ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Fired ajax abort async = false.
ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Stopping the monitoring of the keep alive.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Client subscribed to hub 'chathub'.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Negotiating with 'http://localhost:7700/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: webSockets transport starting.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Connecting to websocket endpoint 'ws://localhost:7700/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=Iu%2BQ6Y9OhJoGSDi6J%2FoC0duclYpWcU1FtCvGj%2B9Jvg%2BYCW8MbyptAMV5E2MyApaYzucZjotsOQyIIzbAua9WfK4G59tZMn4j%2FNXdLAygbYvgvsUFWF6AhG6YoLiU3Oqy&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=8'.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Websocket opened.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: webSockets transport connected. Initiating start request.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: The start request succeeded. Transitioning to the connected state.
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
jquery.signalr-2.2.1.min.js:9 

[10:20:22 GMT+0200 ] SignalR: Triggering client hub event 'SetConnectionId' on hub 'ChatHub'.

我已经创建了与信号器的连接,如下所示:

$(function () {

    var chat = $.connection.chatHub;

    chat.client.setConnectionId = function (connectionId) {
        console.log("ConnectionId: ", connectionId);
    };

    $.connection.hub.url = 'http://localhost:7700/signalr';
    $.connection.hub.logging = true;
    $.connection.hub.start().done(function () {

    });

});

如何修复此警告?

1 个答案:

答案 0 :(得分:1)

这是因为signalR正在进行同步中止调用。 https://github.com/SignalR/SignalR/issues/3624