我在 MVC5 项目中使用 SignalR 2.2.0。 SignalR 在客户端依赖于 JQuery。
JQuery 最近发布了新版本,我从 Nuget 更新了它,特别是从版本 2.2.4 更新到 3.0.0.1,但随后 SignalR 停止工作。 JavaScript 中的启动命令“$.connection.hub”失败。 经过很长时间的绞尽脑汁,我将 JQuery 降级到 2.2.4,一切又恢复正常了。
我是唯一遇到这个问题的人吗?有什么解决办法吗?
谢谢。
最佳答案
您必须自己编辑signalR代码,在jquery 3中,他们删除了加载事件的快捷方式:
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/
所以在文件 jquery.signalR-{version}.js
中:
您必须更新此行:
_pageWindow.load(function () { _pageLoaded = true; });
致:
_pageWindow.on("load",function () { _pageLoaded = true; });
关于JQuery 3 和 SignalR 2.2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37952332/