Including Javascript files - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Including Javascript files (/showthread.php?tid=53050) Pages:
1
2
|
Including Javascript files - El Forum - 07-09-2012 [eluser]Alhazred[/eluser] I've already read many threads about this, but no one solved my problem. I've put my js file into a folder named js into the root, at the same level of CI index.php Inside the view where I want to use the js file I've put [script type='text/javascript' src='<?php echo base_url() ?>js/check.js' ][/script] I've used the proper < and > in place of [ and ] in my code. looking at the page source code the src is correct: http://localhost/js/check.js but the code doesn't work. If I click on the link shown in the page's source code I get an error for file not found. May that depend on the htaccess file and rewrite rules? I've used htaccess to remove the index.php from the url. If htaccess is not a problem, what should I try to fix this problem? Including Javascript files - El Forum - 07-09-2012 [eluser]CroNiX[/eluser] depends on your htaccess rules, which you should post. Most likely you aren't allowing access if you are using one of the htaccess files floating around the forums and haven't adjusted it properly. Use the one with -F and -D rules, not the other which needs constant adjustment whenever you add files/directories, which is stupid (you'd have to add your js dir to it to allow access). Code: RewriteEngine On Including Javascript files - El Forum - 07-09-2012 [eluser]Sorry[/eluser] just put this in your .htaccess Code: RewriteEngine on instead of Code: RewriteEngine on there it is also possible to access the favicon.ico, so you just have to put one in your root directory -> oh i was too slow... Including Javascript files - El Forum - 07-09-2012 [eluser]CroNiX[/eluser] That's the lame one I was referring to that needs constant adjustment. Including Javascript files - El Forum - 07-09-2012 [eluser]Sorry[/eluser] [quote author="CroNiX" date="1341853296"]That's the lame one I was referring to that needs constant adjustment.[/quote]ok, your rule is much better, maybe it should be added in the documentation. Including Javascript files - El Forum - 07-09-2012 [eluser]CroNiX[/eluser] It has been for CI3 https://github.com/EllisLab/CodeIgniter/blob/develop/user_guide_src/source/general/urls.rst Including Javascript files - El Forum - 07-09-2012 [eluser]Alhazred[/eluser] [quote author="CroNiX" date="1341852784"] Code: RewriteEngine On Thanks, this solved the problem My htaccess was Code: RewriteEngine on Including Javascript files - El Forum - 07-09-2012 [eluser]Sorry[/eluser] yeah, it has to be changed here: http://ellislab.com/codeigniter/user-guide/general/urls.html Including Javascript files - El Forum - 07-10-2012 [eluser]Near[/eluser] are you sure this link is correct? http://localhost/js/check.js should it be http://localhost/application/js/check.js Including Javascript files - El Forum - 07-10-2012 [eluser]Alhazred[/eluser] [quote author="Near" date="1341916102"]are you sure this link is correct? http://localhost/js/check.js should it be http://localhost/application/js/check.js[/quote] Yes, I'm sure, as suggested all over the websites I've checked, I put my static contents such as javascript, css and image inside my site's root, so at the same level as index.php, so the first link is correct. By the way, I've solved the problem changing my htaccess as said above. |