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

I am getting an undefined connection id in signalr javascript client - Stack Overflow

programmeradmin4浏览0评论

According to all documentation that i have e across i should be able to call $.connection.hub.id AFTER my connection has been started. this is my code:

    var handshake = $.connection.handshakeHub;
    $.connection.hub.start().done(function () {
        console.dir($.connection.hub);
        console.log('connection started with id: ' + $.connection.hub.id);
        self.parentConnectionId = document.cookie.replace(/(?:(?:^|.*;\s*)connection\s*\=\s*([^;]*).*$)|^.*$/, "$1");
        handshake.server.connect(self.parentConnectionId, $.connection.hub.id);
    });

I am successfully connecting and the handshake proxy connect call hits the server so it is not like the connection is bombing. I have also inspected the property in the dev tools after the connection and the ID is still undefined.

I have tried this with version 2.1 and 2.2 of Signalr and no luck. Anyone have any experience with this? This is killin me.

According to all documentation that i have e across i should be able to call $.connection.hub.id AFTER my connection has been started. this is my code:

    var handshake = $.connection.handshakeHub;
    $.connection.hub.start().done(function () {
        console.dir($.connection.hub);
        console.log('connection started with id: ' + $.connection.hub.id);
        self.parentConnectionId = document.cookie.replace(/(?:(?:^|.*;\s*)connection\s*\=\s*([^;]*).*$)|^.*$/, "$1");
        handshake.server.connect(self.parentConnectionId, $.connection.hub.id);
    });

I am successfully connecting and the handshake proxy connect call hits the server so it is not like the connection is bombing. I have also inspected the property in the dev tools after the connection and the ID is still undefined.

I have tried this with version 2.1 and 2.2 of Signalr and no luck. Anyone have any experience with this? This is killin me.

Share Improve this question asked Jan 16, 2015 at 17:26 kmacdonaldkmacdonald 3,4712 gold badges20 silver badges22 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

For anyone else that may have been googling/searching this (like me), ensure you've started your hub and it's connected.

$.connection.hub.start().done(function () {
    console.log("id : %o", $.connection.hub.id);
});

I am an idiot. I had the proxy script tag included in two different spots in my solution. Removing one fixed the issue.

I have tried handshake.connection.id and this worked for me

发布评论

评论列表(0)

  1. 暂无评论