Sorry for asking this silly question.
I got stuck to include a javascript file in my html page in a php project. when I try this it works fine-
<script type="text/javascript" src="script.js"></script>
But when I want to load the script.js file from my js directory it does not work. I tried-
<script type="text/javascript" src="js/script.js"></script>
N.B: I have my js folder in the same myproject directory alongside my index.php and script.js is located inside the js folder.
Advertisement
Answer
Since there are subfolders in your project, to have js/script.js working you have to set your base path in your index.php like
echo '<base href="http://localhost/myproject/">';
then the following line as a normal html
<script type="text/javascript" src="js/script.js"></script>