I am new at web development and I want to upload a main.js scrip in my PHP file but it gives me this error
I used a script tag to upload the js file like this:-
<script type="text/javascript" src="../assets/js/main.js"></script>
This could be due to many things:
Check ad/script blocker
Check if the browser can load it from the view page source option
Try pasting it before all scripts call it could be due to some functions in previous scripts, I faced this issue before.
This might help.
Related
HTML and CSS files are working perfectly on my live server. But every time I lead to a .js script it will not be shown on my live server. If I try to load the .js file directly through the URL it shows "Cannot GET /line.js". I already tried out everything I've found on the internet but it's still not working. Here are the points I checked/did:
Installed Code Runner
Installed Node.js = node.js system path done
Settings = Live Server Config = specified browser
"liveServer.settings.CustomBrowser": "chrome" on JSON settings
.js file is in a separate folder and accessed via <script src="line.js"></script> on index.html
Chrome is set as default browser on my system
Thanks for your inputs.
If the js file is in a separate folder, you need to provide the exact route to the folder in the script tag, since in the current form it is trying to find the js file in the root directory. The script tag should look like this:
<script src="FOLDER_NAME/line.js"></script>
It's possible that your javascript file is being loaded before the HTML page is rendered. You can try adding "defer" to your script tag like this:
<script src="demo_defer.js" defer></script>
I have been coding up a localhost, and I made the localhost by using of course a JavaScript file to do so, and I then made it reference an HTML file. However, I noticed that when I am using localhost to serve up the HTML file I get this error:
"GET http://localhost:3333/filetesting.js"
The filetesting.js is that js file, there are also other things I'm referencing too, like websites. I'm referencing it by using script tag src.
I looked at the network on developer tools of it and it says it's a 404 error not found. I'm trying to figure out how to reference my script tag src's without having localhost:3333 go before it.
When I run the HTML file without using the localhost, it works just fine when it comes to the script tag src's. If you do not entirely understand what I'm asking for, just ask.
Assuming that your script will always reside in the root level of your website, you can simply target it with the root-relative prefix /:
<script src="/filetesting.js"></script>
This will load your script from the root, regardless of the site the file is hosted on. For example, on http://localhost:3333/ it will load the file from http://localhost:3333/filetesting.js, and from http://localhost:3333/folder/, it will attempt to load the file from the same location.
If you move your files over to a proper website, it will still work the same way: www.example.com will look for the file at www.example.com/filetesting.js, and www.example.com/folder/ will look for the same file at www.example.com/filetesting.js.
Hope this helps! :)
I have loaded my express app on a server (I used heroku). When I test my app locally it works fine but when I load the page on the web it gives me a net::ERR_BLOCKED_BY_CLIENT saying that it is not able to load a JS file that I define in the HTML page:
<script src="./index.js"></script>
If I try to go to: http://<my-page>/index.js it is able to load the file successfully.
Why this doesn't work?
(If you need more information tell me what I need to add)
I finally solved my problem. There was a problem with the Avira Chrome extension that was blocking the file from loading. I simply added my page to the whitelist and it started working as supposed.
Below code,
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script type="text/javascript">
console.log(jQuery);
</script>
works fine in firefox browser after src is modified to "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"(remote file) or "../js/jquery.min.js"(local file)
Otherwise, dev console gives Reference error: jQuery is not defined
I would like to test the code with remote library but not local
How do I understand this problem?
Leaving the scheme off the URL means that it is scheme relative.
If the HTML document is loaded over HTTP then the JS will be too.
If the HTML document is loaded over HTTPS then the JS will be too.
If the HTML document is loaded over FILE then … the JS won't be because file://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js doesn't exist.
Do your local testing on a local web server, don't load your HTML directly from your file system.
As mentioned by Mosh Feu, if you run a file locally, without a webserver, you cannot use protocol relative paths to load jQuery. That's because it is trying to find a local reference: file://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js.
Well, you could if you have jQuery locally in a folder /some/where/jQuery.js and you reference it with <script src="//some/where/jQuery.js>
So yes, if you're running pages from the disk directly, you must specify the protocol if you want jQuery from a CDN. See the first comment on http://www.paulirish.com/2010/the-protocol-relative-url/
Save yourself some trouble, install a local web server.
You must be viewing the file locally without using a web server which results in a wrong URL when the protocol is not explicitly specified.
Im attempting to utilize some custom script and css files within an asp page. In Visual Studio 2010 I am not getting any warnings or errors as to the status of these files, but when I attempt to run the page, and I open the javascript console I get the error:
Failed to load resource: the server responded with a status of 404 (Not Found)
Here's how I am attempting to load the files in my ascx file:
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.scripts.js"></script>
<script type="text/javascript" src="scripts/jquery.alerts.js"></script>
<link href="styles/jquery.alerts.css" rel="stylesheet"/>
Anyone know whats going on here, why the browser can't locate the files but visual studio can?
This happens when the location of the .aspx file is different to the location of the user control (ascx).
When the user control is rendered in the browser it will actually have the location of the .aspx and tries to make the reference from that point. Whereas in VS, it will try to make the reference to the file from the .ascx location.
Therefore, try referencing the files as if you were making the references from the .aspx file location. It shouldn't give you any error when rendering that page.
I've upvoted aleafonso's answer since he's correct. Now, to solve this issue, you can use the ResolveClientUrl method.
Something like this:
<script type="text/javascript" src='<%=ResolveClientUrl("scripts/jquery.js"%>'></script>