2

I am using CodeIgniter. I am trying to load an external javascript file.The .js file is placed in the views folder itself.

I use the following code for loading the js file in the view file

<script src="/countdown.js" type="text/javascript"></script>

But it does not load the js file. The same code works if i simply put it in the view file. Can someone point out what i am missing here.

4
  • nopes .. I am not getting any errors .. though when i go into the source code in the browser and click the link to open the js file ,i get The requested URL /ci/countdown.js was not found on this server Commented Aug 10, 2012 at 23:22
  • If you have Chrome installed:(1) Right click(2)Inspect elements(3)Network(4)Reload the page(5) Now can you paste the file's URL, and the status error(404, etc)? Commented Aug 10, 2012 at 23:23
  • @torsten : have tried ..didnt work Commented Aug 10, 2012 at 23:32
  • @aziz : http://localhost:81/ci/countdown.js status is being shown as cancelled Commented Aug 10, 2012 at 23:36

1 Answer 1

3

One possible solution is what I had to do when I had to include things such as CSS and Javascript.

What I did, was put the css and js files into the root of the codeigniter directory (the directory that the application folder is in, and called them like this:

<script src="<?php echo base_url("countdown.js"); ?>" type="text/javascript"></script>

This will make the call from the directory that application/ is contained in.

Good luck!

Sign up to request clarification or add additional context in comments.

2 Comments

This works ..thanks But is not possible to load from any directory??
Here's a similar question that might help with your other question above: stackoverflow.com/questions/5961287/… I store my app dir above root, so always store css, js etc in separate directories to the app dir. This is for security reasons. But how you do it is up to you. Remember and set your base_url in config.php too is you are going to use base_url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.