I am coding a PHP website homepage using a MAMP localhost server. I would like to connect the main HTML file to a javascript file, but when I do so, none of the javascript is executed, and an error that says Failed to load resource: the server responded with a status of 404 (Not Found) appears.
I have tried using the absolute file path when including the file under the src attribute (though the js file is in the same folder as the main html file anyway). I tried turning the server on and off and reloading the page several times, but the error still appears.
<head>
<script type="text/javascript" src="/homescript.js"></script>
</head>
<body onresize="changeHeaderDisplay()" onload="responsiveCarousel()">
</body>
The forward slash at the beginning of the filename in the script tag is the problem :
src="/homescript.js"
When your browser sees a forward slash, it assumes the file is at the top level of the domain it's searching. So if your html file is at:
file:///Users/Jack/test_program/index.html
it is searching for homescript.js at:
file:///homescript.js
To make it search for it at:
file:///Users/Jack/test_program/homescript.js
simply remove the leading forward slash:
<script type="text/javascript" src="homescript.js"></script>
Edit: On a website, it's the same phenomenon:
With leading slash:
http://www.example.com/homescript.js
Without leading slash: http://www.example.com/test_program/files/homescript.js
Related
I am following the instruction to use Numeral.js.
I insert <script src="numeral.min.js"></script> before the end of my <body>.
when I reload the page i get the following error:
GET file:///<project_path>/numeral.min.js net::ERR_FILE_NOT_FOUND
And if I use numeral(1000).format('0,0') I get ReferenceError: numeral is not defined
same problem if I use <script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>:
GET file://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js net::ERR_INVALID_URL
What am I doing wrong? how do you use numeral.js?
Try to either :
specify https:// instead of // at the beginning of the cdn url
copy numeral.min.js next to your html file on disk
// means "use the same scheme as current page"
If you opened your html file by opening the file from your disk in your browser, it's url will be a file:// url, hence the error when you tried accessing the file with //<cdn>/...
An alternate way is to start a webserver on your machine and access your page through http(s)://localhost:someport/my test.html
In my static webpage loaded from IIS (v8.5.9600), I include jquery with the following:
<script type="text/javascript" src="js/jquery.min.js"></script>
And when loading the page in the firefox browser I get the following error in my console:
Uncaught SyntaxError: illegal character [Learn More] jquery.min.js:1
If I load it from the CDN, everything is fine, my code runs and I get no errors (my code is in the html page and thus not included from another script).
<script type=“text/javascript” src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js">
I downloaded the file from the CDN and copied it directly into IIS, but when it loads I still get the error in Firefox about an illegal character.
Both of the files from the CDN and IIS load up, so that is not the issue, but I did notice that when the file is loaded from the CDN it looks like this:
But when I load it from IIS (v8.5) it looks like this:
P.S. I tried loading a simple script from IIS (not from the CDN) as well and I get the same error. Is it something to do with IIS's settings?
Check the browser network tab snapshot which shows the script file name and make sure it loads up on its own from the URL you specfied in the src attribute of your <script> tag.
Your Javascript <script> include tags need to have the charset="utf-8" attribute so that the browser requests the script from the server in the utf-8 encoding.
I am testing an html webpage and it is failing to load a local jquery.json-2.4.0.js. I am testing the html page locally from chrome. When the page loaded I get a net::ERR_FILE_NOT_FOUND.
Why is it unable to load the file? This file has been moved from a different server (which it was working fine on), but the directory paths are the same (I double checked the path ).
Here is my line:
<script type='text/javascript' src='/webforms/ExperianEmailJsScripts/jquery/js/jquery.jsonp-2.4.0.js'></script>
Remove the first / in the path. Also you don't need type="text/javascript" anymore in HTML5.
This error means that file was not found. Either path is wrong or file is not present where you want it to be. Try to access it by entering source address in your browser to check if it really is there. Browse the directories on server to ensure the path is correct. You may even copy and paste the relative path to be certain it is alright.
I got the same error using:
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,700,700i,900,900i" type="text/css" media="all">
But once I added https: in the beginning of the href the error disappeared.
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400i,700,700i,900,900i" type="text/css" media="all">
Same thing happened to me. Eventually my solution was to navigate to the repository using terminal (on mac) and create a new js file with a slightly different name. It linked immediately so i copied contents of original file to new one. You also might want to lose the first / after src= and use "".
Sometime when you downloading a project from other people, they might have some special customization. So, in my case I downloaded this project https://github.com/thecodercoder/fem-easybank
And got these errors: Failed to load resource: net::ERR_FILE_NOT_FOUND
That happed because the creator was using the /dist folder customization.
https://youtu.be/aoQ6S1a32j8?t=309
SOLUTION: you open Notepad++ press: Ctrl + F for search
find all folders that starts with / as in the picture and replace with norma ones like:
/dist/ to dist
Instead of:
path.join(__dirname, '/dcp-electron/index.html')
you should add a dot at the start of the path, to indicate that the path is relative:
path.join(__dirname, './dcp-electron/index.html')
this can happen when you have the base tag, as explained in other answers
<base href="/">
For some reason my html file's request for my jquery.js file fails, however when I enter that exact url into a new tab in the browser, I get the exact jquery.js file I am trying to get when the website loads.
My code is as such:
<script src="js/jquery.js"></script>
and my website is here. If you append jquery.js to the root, you will see the exact file.
Can anyone explain why the file isn't properly retrieved when the website loads?
Any help is greatly appreciated.
At the beginning of your HTML file is this:
<!DOCTYPE html>
<html manifest="appcache.appcache">
The appcache.appcache refers to the file appcache.appcache whose content is:
CACHE MANIFEST
# V1.65 1-18-2013 10:15 PM
# cache
index.html
about.html
services.html
contact.html
css/signika.css
css/mq.css
css/index.css
css/about.css
css/services.css
css/contact.css
assets/signika_400.woff
assets/signika_600.woff
js/html5.js
js/index.js
js/mq.js
js/services.js
mail.php
images/chicken.png
images/salad.png
images/soup.png
images/steak.png
images/wontons.png
As you can see jQuery.js is not there. I suggest you to add js/jQuery.js into a new line and try again.
I figured this out by:
Running the Fiddler software side by side with Chrome (on Windows).
Loading your website in Chrome with Developer Tools (Ctrl+Shift+I on Windows, Command ⌘+Option ⌥+I on Mac), then go to the Network tab.
Then I see that Chrome loads appcache.appcache from the second time onwards and there's an error when loading jQuery.js.
The manifest attribute refers to the HTML5 cache manifest file.
Tutorial:
http://www.html5rocks.com/en/tutorials/appcache/beginner/
More references:
http://caniuse.com/#search=manifest (browser compatibility)
http://en.wikipedia.org/wiki/Cache_manifest_in_HTML5 (wiki)
https://www.google.com/search?q=html5+manifest
It's probable that the HTML file containing the script header in question is not in the "root" but perhaps in the same JS folder or somewhere else.
So technically this should work:
<script src="/js/jquery.js"></script>
Just keep in mind that this path is relative.
I have an HTML page generated by an objective-C application and I want to load and open it in a local directory (not in a web server). The javascripts jquery.js and jquery.plot.js are stored in the same directory before the page is loaded.
I made the HTML page by following closely the examples available on http://flot.googlecode.com/
The scripts are declared in the HTML page as follows :
<script src="jquery.js" language="javascript" type="text/javascript"></script>
<script src="jquery.flot.pack.js" language="javascript" type="text/javascript"></script>
When I open the page, the expected graph (generated by the scripts) doesn't show up and I have the following syntax error in the javascript console :
Uncaught SyntaxError: Unexpected token ILLEGAL
The script source in the javascript console is made of strange (chinese ?) ideograms which are obviously "unexpected token" if it is what the browser sees.
I have the same problem with Chrome, Firefox and Safari.
The problem is not systematic because sometimes, it works !.
I have made tests with files prepared manually and again it works sometimes only.
I have also copied the same file which didn't work in another directory where the jquery scripts were present and, surprise, it worked ! but not always...
I have exhausted all my ideas on this problem and your help will be very much appreciated
Did you copy the JavaScript from an external source? I know I have had problems when copying from JSFiddle for example. Try removing any whitespace and see if that will get rid of the illegal token error.
I just had this problem and it was because the server on which my javascript was being hosted wasn't configured to send the javascript file with the correct MIME type. See this question.
Instead of fixing my server, I just opted to use a CDN path from cdnjs.com:
//cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.min.js