1

I have the following directory structure

*application
*media
*system

I place my js files inside the media/js folder but when i try to include the js file in my view

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

It gives the following error

Resource interpreted as Script but transferred with MIME type text/html

and it does not load the js file.. even the jquery file.. can sombody tell me what is the problem. what I may be doing wrong ?

7
  • where do you place the script code with view? Commented May 6, 2012 at 12:26
  • it is in the application/views folder Commented May 6, 2012 at 12:28
  • i.e in a view file within application/views Commented May 6, 2012 at 12:29
  • try this:<script type="text/javascript" src="../../media/js/common_functions.js"></script> Commented May 6, 2012 at 12:29
  • the problem is not in the path.. Commented May 6, 2012 at 12:31

4 Answers 4

2

try this:

$config['javascript_location'] = 'http://localhost/codeigniter/themes/js/jquery/';

To initialize the jQuery class manually in your controller constructor, use the $this->load->library function:

$this->load->library('jquery');

http://codeigniter.com/user_guide/libraries/javascript.html

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

Comments

1

try this:

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

1 Comment

actually it do works fine If i give the absolute path.. thanks for your help !! cheers :)
1

For standard and useful approach, try this one:

<script type="text/javascript" src="<?=base_url()?>media/js/common_functions.js"></script>

Comments

0

freaking hell..! wasted like half an hr on this. I used the url guide to remove index.php. Now I had my stuff in public directory in the root folder with .htaccess file as follows

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

So just make sure the folder is included in the RewriteCond $1 ... line as follows

RewriteCond $1 !^(index\.php|**public**|robots\.txt)

Hope this helps someone.

Comments

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.