-3

I'm trying to run a function within a JavaScript file when a button is clicked.

I put the JavaScript file in a scripts folder, and linked to it within my HTML file. It didn't work. I added a link to the physical file on the webpage. I got a 404, despite the file definitely being there.

Here's the structure:

enter image description here

Here's where I link to the file: enter image description here

Here's the actual button and the created link to the file: enter image description here Here's the error I'm receiving: enter image description here

Literally anything will help

thanks

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
rckl
  • 15
  • 1
  • 2

1 Answers1

-1

The URI is 127.0.0.1:5000/scripts/file.js. The

<script src="scripts/file.js"></script> 

is not using relative location to the folder but rather to the server. You need to do

<script src="templates/scripts/file.js"></script>

If this templates directory is nested with any other directories from the root, then they too need to be prepended to the src location.

Esaith
  • 706
  • 9
  • 12
  • This unfortunately didn't fix it. – rckl Jun 01 '18 at 03:54
  • Try clicking (or double click) on that 404 within the network tab. It may show you where it thinks it is on your physical drive. That may point you to where the confusion is. – Esaith Jun 01 '18 at 03:59
  • There's no indication on the network tab of where it physically came from. I think I'm going to pick this up tomorrow with the intention of finding a way to locate where it thinks it is in the physical drive. Thanks for your help. – rckl Jun 01 '18 at 04:04
  • This URL is definitely relative to the folder. Relative to the server would be `src="/scripts/file.js"`. – Barmar Jun 01 '18 at 04:09
  • 1
    he said in a comment above that the full URL in the Network tab is `http://127.0.0.1:5000/templates/scripts/file.js` – Barmar Jun 01 '18 at 04:10
  • I noticed you may be using Firefox. Try opening in Chrome, if available. I, too, was unable to view the physical drive when double clicking on the 404 in Firefox, but double clicking on the error in Chrome showed me the physical drive for my IIS setup. – Esaith Jun 01 '18 at 04:15
  • Or, if still in firefox. Right click on the 404 line for the Content Menu. Open in new tab. – Esaith Jun 01 '18 at 04:17
  • Both of these suggestions just reopened the same 127.0.0.1 link. – rckl Jun 01 '18 at 04:22