最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Javascript and jQuery not working in htdocs folders of xampp - Stack Overflow

matteradmin6PV0评论

So I've created a website using HTML,CSS and Javascript and saved it on the desktop. I then created a local server using xampp. I placed this html file in the htdocs folder of xampp. The file is named "foodlist.html". Whenever I try opening this fine in the webbrowser as localhost/foodlist.html, the jQuery and Javascript contents of the file fail to display. Here is a part of the code:

<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href=".3.4/css/bootstrap.min.css">
<script src=".3.4/js/bootstrap.min.js"></script>
<script src=".11.3/jquery.min.js"></script>
<script id="javascript" src="file:///C|/Users/Akshat/Desktop/Project/JS-jQuery/addnremove.js"></script>

How can I make the javascript and jquery code work each time I open the file on the browser with the /localhost?

So I've created a website using HTML,CSS and Javascript and saved it on the desktop. I then created a local server using xampp. I placed this html file in the htdocs folder of xampp. The file is named "foodlist.html". Whenever I try opening this fine in the webbrowser as localhost/foodlist.html, the jQuery and Javascript contents of the file fail to display. Here is a part of the code:

<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn./bootstrap/3.3.4/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn./bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script id="javascript" src="file:///C|/Users/Akshat/Desktop/Project/JS-jQuery/addnremove.js"></script>

How can I make the javascript and jquery code work each time I open the file on the browser with the /localhost?

Share Improve this question asked Jun 29, 2015 at 21:24 Akshat TyagiAkshat Tyagi 471 silver badge5 bronze badges 2
  • You need to convert the path of addnremove.js to a URL. The directory path that you have will most likely not work. Something like http://localhost/path/to/addnremove.js – Maximus2012 Commented Jun 29, 2015 at 21:27
  • Additionally, if the html and the JS file are in the same directory, then you should be able to specify the file name in src attribute of script tag. It is probably a good idea to create a proper directory structure for your project with directories for css/js and images etc. This along with proper configuration file will make your code/project more portable when you move it to a different server or to a different location on same server. – Maximus2012 Commented Jun 29, 2015 at 21:28
Add a ment  | 

2 Answers 2

Reset to default 2

The file:///C|/Users/Akshat/Desktop/Project/JS-jQuery/addnremove.js is not a valid address, such kind of linking even with a right address will not work for security reason..

For it to work, e.g. your XAMPP directory is "C:\xampp", you can copy the "C:\Users\Akshat\Desktop\Project\JS-jQuery" folder into "C:\xampp\htdocs" folder and link your "addnremove.js" file this way:

<script id="javascript" src="http://127.0.0.1/JS-jQuery/addnremove.js"></script>

You can even change the http://127.0.0.1/ address with http://localhost/.

it looks like "file:///C|/Users/Akshat/Desktop/Project/JS-jQuery/addnremove.js" is not a proper link to a file. try putting this file relative to your html like you did with main.css

Post a comment

comment list (0)

  1. No comments so far