php - Use function in another JavaScript file? -
php - Use function in another JavaScript file? -
i have php file next @ bottom:
<script src="js/functions.js"></script> <script type="text/javascript"> alert(testfunction()); </script>
i have js file called functions.js
next function:
function testfunction() { homecoming 'hello world!'; }
why console show referenceerror: testfunction not defined
when i've imported right js file , called function?
works fine here: (i know not needed simple)
http://jsfiddle.net/6flny/1/
the thing is... create sure script file correctly linked page.
here brief description of file paths when inserting path in src
tag:
./
means current directory
../
means parent of current directory, not root directory
/
root directory
myfile.text
in current directory, ./myfile.text
../myfile.text
1 level above , /myfile.text
lives in root directory.
so you:
<script src="js/functions.js"></script>
would mean functions.js
in js folder in current directory
javascript php jquery
Comments
Post a Comment