This could look like a noob problem to some... I hope it is. I have a web app made using the php slim framework. I have the following hierarchy:
I'm trying to reference script1.js from template1.phtml and script2.js from template2.phtml. I'm doing the following:
template1.phtml
<script src="app/scripts/script1.js"></script>
template2.phtml
<script src="app/scripts/script2.js"></script>
template1 works just as expected but template2, even when it's practically the same, gives the following error:
GET http://localhost:8888/app/scripts/script2.js net::ERR_ABORTED 404 (Not Found)
WHAT I'VE TRIED
Set the full script2.js path to the src (using a few ../) which obviously works but is not the right approach.
NOTES
I'm using MAMP to test my app with php5.* When I run the app by using the command line and php7 both scripts are referenced properly.
to reference script1.js from template1.phtml , you could use ../../../app/scripts/script1.js
Related
I have an index.html file with <script src=”sc2.js”></script> in the head section. In the same directory I have file sc2.js that has some really simple JavaScript code I wanted to test to see what it prints. The html displays correctly in my browser, but the console says:
index.html:8 GET file:///Users/myname/projectfile/%E2%80%9Dsc2.js%E2%80%9D net::ERR_FILE_NOT_FOUND
Am I missing something to make it possible to run the code in my browser? I can still run old JavaScript projects in the browser with no problems. I also tried to move the script tag around and add the full path, which made no difference. The code works in jsfiddle.net. I'm using Chrome Canary.
I am trying to run Jquery without internet connection, and I have problem with the path to it. My project is in ASP.NET core.
When I entered code like this:<script src="jquery-3.4.1.js"></script>
and I got this error in my browser console :
GET https://localhost:44374/myProject/jquery-3.4.1.js net::ERR_ABORTED 404
I inserted Jquery file right into my root directory and to several others, but that did not work.
So how do I prevent c# from thinking that jquery-3.4.1.js is an action inside my controller ? (I do not want to use absolute path)
Pass root directory './' and certify that file has the same name.
<script src="./jquery-3.4.1.js"></script>
I'm trying to make a chat application using socket.io and Node.JS. In my html file called index.html, I am trying to use a script tag to point to a script file called bundle.js that contains a browserified set of variables and functions.
The problem is, despite referencing the proper path in my src attribute, the tag seems to include a bundle.js within my localhost:3000.
Oddly enough, when viewing this bundle.js with developer tools, the content seems to be identical to that of my index.html file. This creates a syntax error as the JavaScript file contains html syntax from my html file. Any ideas why this might be?
<script src="bundle.js" type="text/javascript"></script>
This is how the script tag appears in my html file.
This is a link to a screenshot of my developer tools (New here so not enough rep to post the actual pic)
As we can see bundle.js is open in developer tools is Html code, not js that's why error is shown in first line, or there is something wrong in webpack configuration.
I am getting problem in referencing Javascript file.
My all js files reside in my js folder:MyProject/Js/*.js
Now on my master page i am refering my file like this:
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
Error showing in console:
SyntaxError: expected expression, got '<'.
On searching i have found that this issue comes due to inappropriate referencing of js files so i have resolve this error by doing this:
<script src="../js/jquery-1.9.1.js"></script>
<script src="../js/jquery-1.9.0.min.js" type="text/javascript"></script>
This above solution works when my .aspx page would be like this:
MyProject/Admin/Abc.aspx //This will work
But problem will occur when any of my .aspx page would be like such:
MyProject/Admin/Subfolder/Abc.aspx // This will not work
My Abc.aspx page contains master page but now in this case this will not load my js files due to ../
So can anybody tell me whats the correct way to reference js files which will work in both the cases??
Note:I am referencing all js files in to my master page and my master page is in:
MyProject/MasterPage.Master
I think you can give a try:
1) Use Bundling to reduce the loading time (Your script will be shorter as well)
2) Use ~/ instead of ../ to make your script/code work even if you relocate the pages.
You can easily find the scripts and codes of jquery bundle if you create a new ASP.NET application in Visual Studio.
I use jQuery in my web project.
When I use local reference like this;
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
I receive this error:
$ is not a function
but when I use the Google reference in my project like this
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
Everything works fine.
It is noteworthy I use telerik component in my project.
It looks like the problem is simply that the relative path for the import is incorrect. Hence it's not loading jQuery and the call to $(document).ready is undefined.
You need to correct the path to the Scripts folder.
most probably ur not loading jquery right
Take these steps :
use developper tools in your browser (my favorite is firebug for firefox)
go to the scripts tab and check if jquery.js is there
if its there and its empty, check the url, maybe ur relative path is incorrect. to verify it you can put the url in your browser and fix it until the js file loads