Home > front end >  Html cannot load javascript?
Html cannot load javascript?

Time:03-24

I'm sorry about the fact that I'm a newbie, if the question is not clear, please notify me again, I will add information. I have a sample code , but it cannot load js. Can someone tell me how to solve?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/signalr.js"></script>
    <script src="/js/Cnn.js"></script>
    <title></title>
</head>
<body>
    <h1>Qoo</h1>
</body>
</html>

the error:

Failed to load resource: net::ERR_FILE_NOT_FOUND

enter image description here

enter image description here

And I have try this way,but it still cannot work

<script src="/wwwroot/js/signalr.js"></script>

or

<script src="~/js/signalr.js"></script>

CodePudding user response:

It all depends on where the HTML file is, relative to the JS file.

If the index file is in the root of that folder and the JS in a sub-folder, the correct code would be:

<script src="js/signalr.js"></script>

The above code uses a relative URL as does your code however, your code is relative to the root directory and my example is relative to your current working directory.

If your URL in the browser has a driver letter at the start of it, then the JS would be loaded from a JS sub-folder in the root of that drive. For example, if the URL is C:\wwwroot\index.html then the browser would attempt to load the JS file from C:\js\signalr.js rather than C:\wwwroot\js\signalr.js, where the latter is the correct location.

CodePudding user response:

You can try with:

./js/signalr.js
  • Related