Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

asp.net mvc - JQuery 3 and SignalR 2.2.0

I use SignalR 2.2.0 in a MVC5 project. SignalR depends of JQuery in client-side.

JQuery recently released new version, I updated it from Nuget, specifically from version 2.2.4 to 3.0.0.1, but then SignalR stopped working. Startup command "$.connection.hub" in javascript fails. After a long time head scratching, I downgrade JQuery to 2.2.4 and everything is fine again.

Am I the only one getting this problem? There is any workaround?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You must edit the signalR code by yourself, In jquery 3 they removed the shortcut for load event :

Breaking change: .load(), .unload(), and .error() removed

These methods are shortcuts for event operations, but had several API limitations. The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $(img).on("load", fn).

https://jquery.com/upgrade-guide/3.0/

so in the file jquery.signalR-{version}.js :

you must update this line :

_pageWindow.load(function () { _pageLoaded = true; });

To :

_pageWindow.on("load",function () { _pageLoaded = true; });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...