admin管理员组文章数量:1410705
Currently I am creating a chat. I want to use AspNetCore (2.2) SignalR. I have followed the instructions on .2&tabs=visual-studio but now I am facing the following issue: When I run my client in IIS the following error occurs:
ReferenceError: signalR is not defined[Learn More] script.js
anonymous http://localhost:20610/js/script.js
I searched the web and found out that in NodeJS you have to use
const signalR = require("@aspnet/signalr");
But in my case I am using plain javascript so I thought I don't need to add this line. Am I right?
Here is my html and the beginning of my js code:
<head>
<title>abc</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style/style.css">
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/signalr.min.js"></script>
<script src="js/script.js"></script>
</head>
var connection = new signalR.HubConnectionBuilder().withUrl(base).build();
Are there any suggestions how to get this working?
Thanks :)
Currently I am creating a chat. I want to use AspNetCore (2.2) SignalR. I have followed the instructions on https://learn.microsoft./en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.2&tabs=visual-studio but now I am facing the following issue: When I run my client in IIS the following error occurs:
ReferenceError: signalR is not defined[Learn More] script.js
anonymous http://localhost:20610/js/script.js
I searched the web and found out that in NodeJS you have to use
const signalR = require("@aspnet/signalr");
But in my case I am using plain javascript so I thought I don't need to add this line. Am I right?
Here is my html and the beginning of my js code:
<head>
<title>abc</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style/style.css">
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/signalr.min.js"></script>
<script src="js/script.js"></script>
</head>
var connection = new signalR.HubConnectionBuilder().withUrl(base).build();
Are there any suggestions how to get this working?
Thanks :)
Share Improve this question asked Jan 27, 2019 at 13:15 CLRW97CLRW97 5505 silver badges18 bronze badges 2-
1
Is
signalr.min.js
in thejs
folder? Press F12 in web browser to see whether there is any other error beforesignalR is not defined[Learn More] script.js
– Edward Commented Jan 28, 2019 at 1:52 - The correct answer can be found here: stackoverflow./a/54340966/8492915 – SmallWorld Commented Aug 31, 2023 at 11:16
3 Answers
Reset to default 2SignalR is not defined, so it's not found. Despite the fact you program in plain JavaScript, you still have to include the SignalR. Also, make sure that the path is actually leading to SignalR.
I'm a few months late(new and can't ment either), however, I had the same issue. Not seeing a response here, I figured I'd add one. To clear the error, move your
<script src="~/lib/signalr/dist/browser/signalr.js"></script>
to the Pages/Shared_Layout.cshtml file and place it somewhere, such as under the footer.
This should remove the warning in the console also.
for me this worked
<script src="https://cdnjs.cloudflare./ajax/libs/microsoft- signalr/5.0.8/signalr.min.js"></script>
本文标签: javascriptReferenceError signalR is not definedStack Overflow
版权声明:本文标题:javascript - ReferenceError: signalR is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745036346a2638808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论