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 the js folder? Press F12 in web browser to see whether there is any other error before signalR 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
Add a ment  | 

3 Answers 3

Reset to default 2

SignalR 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