SDK
SDK

Reputation: 1542

Sometimes Signalr was not loading properly

I am developing an ASP.NET MVC application and for notifications I am using signalr.

In my Layout.cshtml page, I referenced the signalr in proper order as shown below

 <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-2.1.3.min.js")"></script>
 @* Signalr part goes here *@
 <script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
 <script type="text/javascript" src="/signalr/hubs"></script>

Below was the code to start the connection

if ($.connection.broadcastHub) {
        $.connection.hub.start({ transport: 'longPolling' }).done(function () {
        });
}

Issue

Now, everything working fine if signalr loads correctly but sometimes the signalr was not loading correctly as expected and it throwing the below error in console

enter image description here

If I refresh the page again(ctrl + F5) its loading correctly and working as expected but sometimes signalr throwing the above error and i am not able to resolve this issue.

I found similar question SignalR: Sometimes Negotiating requests returns 404 error (Load-balanced) But, I am not doing anything with machine key in web.config and i dont know about anything regarding machine key

Please, can you provide your suggestions to resolve this issue. Thanks

Upvotes: 0

Views: 470

Answers (1)

chenZ
chenZ

Reputation: 930

you should put you js code in a $(function(){...})
if not,when the js code run,some js file not load complete,so you got an error
and sometimes it's ok,sometimes it's error,sometimes it's may a diffrent error

Upvotes: 2

Related Questions