skip to Main Content

Not sure why I am getting a 404 error, path to script index.js seems to be correct as it is in the same folder as the html file. I have tried every path that I can think of, not sure what is wrong here.

enter image description here

enter image description here

enter image description here

I have tried different paths and have tried absolute path as well. Thank you for your help.

Update Server.js:
enter image description here

2

Answers


  1. What server are you running? If you are using npm run serve, then it compiles the js before serving it, and if the js has an error it will come up as a missing file. You can switch to the window and check there for errors.

    If its another server let us know.

    Login or Signup to reply.
  2. I can see your mistake as per your details you did save your html file and js in only one same you did use the that is wrong when you will / then browser will associate that from root directory.Means your html file and js file in the same folder you don’t need to use that "/". you will just write index.js.
    example:

    in other case if your your folder and file settings that just that

    MyWebProject (Folder)
    index.html
    js (Folder)
    index.js

    then you will use that like this:

    The <script> tag you provided is referencing an external JavaScript file named function.js located in the js folder. Let me break down the script tag:

    “ html

    • src="./js/function.js": This attribute specifies the source (filepath) of the JavaScript file to be included. In this case, it is set to ./js/function.js, which means the file is located in the js folder of the current directory (. refers to the current directory).

    • ./: This represents the current directory. So, ./js/ points to the js folder in the current directory.

    • function.js: This is the name of the javascript file to be included.

    So, the script tag is telling the browser to load and execute the JavaScript code from the ‘function.js’ file in the ‘js’ folder of the current directory. Make sure the file path is correct, and the file function.js is in the specified location.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search