Javascript – codeigniter javascript not found error

codeigniterjavascriptjqueryPHPtwitter-bootstrap

First of all, I am sorry for my bad english, I am spanish and I am sorry if I have made something wrong, this is my first post.

I have a problem with loading a javascript file in codeigniter 2.1.4. I didn´t get loaded it in the header of my page. The css files were well loaded. This example attempts to load jquery and bootstrap.

I am following the steps in the documentation of codeigniter and when I create the codeigniter static page "home.php" I want to use bootstrap for design.

The tutorial I followed is this:
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html

My folder structure :

  • htdocs
    • myproject (curriculos)
      • application
        • controller
          • pages.php
        • views
          • templates
            • header.php
          • pages
            • home.php
            • about.php
      • system
      • assets
        • bootstrap
          • css
            • bootstrap.min.css
          • js
            • bootstrap.min.js
        • jquery- 2.1.0.min.js

I have been searching in this forum and others and always I find the same example with base_url() or site_url(). These are mine:

Updated code:

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

My autoload.php with url helper loaded:

$ autoload['helper'] = array('url');

When I try to load the page I get these errors:

GET http://localhost/curriculos/assets/jquery-2.1.0.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found) 

The strangest is that when you click on one of them it shows you that the file type is trying to be loaded as a text/html and not as an application/javascript as usual:

Error loading: file type text/html

Can you help me?

Thank you very much for your reply.

Best Answer

You need to change your .htaccess file so that it no longer rewrites requests made to '/assets'.

In other words, you need your .htaccess file to ignore requests to the 'assets' folder and just let the browser load the url as provided. Try this:

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