问题
I have referenced below two libraries dynamically in my page. When I browse my application below mentioned error did not come in Chrome browser. But in Internet Explorer the error occurs.
var signalRLibrary = document.createElement('script');
signalRLibrary.type = "text/javascript";
signalRLibrary.src = 'jquery.signalR-2.1.2.min.js';
document.getElementsByTagName('head')[0].appendChild(signalRLibrary);
var signlaRHub = document.createElement('script');
signlaRHub.type = "text/javascript";
signlaRHub.src = "~/signalr/hubs";
document.getElementsByTagName('head')[0].appendChild(signlaRHub);
During page load I got below error as SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
回答1:
A JavaScript client requires references to jQuery and the SignalR core JavaScript file. The jQuery version must be 1.6.4 or major later versions, such as 1.7.2, 1.8.2, or 1.9.1. If you decide to use the generated proxy, you also need a reference to the SignalR generated proxy JavaScript file. The following example shows what the references might look like in an HTML page that uses the generated proxy.
<script src="Scripts/jquery-1.10.2.min.js"></script> <script src="Scripts/jquery.signalR-2.1.0.min.js"></script> <script src="signalr/hubs"></script>
These references must be included in this order: jQuery first, SignalR core after that, and SignalR proxies last.
- from ASP.NET SignalR Hubs API Guide - JavaScript Client
Your problem is that, somehow, the order in what you are loading the references is wrong.
来源:https://stackoverflow.com/questions/37522489/signalr-is-not-loaded-please-ensure-jquery-sigalr-x-js-is-referenced-before-s