admin管理员组

文章数量:1323737

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: .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:

Can you help me?

Thank you very much for your reply.

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./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:

Can you help me?

Thank you very much for your reply.

Share Improve this question edited Jul 26, 2017 at 17:08 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked Apr 11, 2014 at 16:35 mrroot5mrroot5 1,9713 gold badges28 silver badges33 bronze badges 4
  • are the images working fine or the same is the problem with the images? – Guns Commented Apr 11, 2014 at 16:40
  • I uploaded a new image with new suggestions.Is this your question? Maybe I didn't understand you well. – mrroot5 Commented Apr 11, 2014 at 23:39
  • Sorry for my english, now I think that I understand you. Yes, the image is correct for the new updated code. Sorry, my text editor teased me when I copied my question from the editor to stack overflow. – mrroot5 Commented Apr 11, 2014 at 23:46
  • I found the problem. The problem is the .htaccess from codeigniter to hide index.php in url ¬¬. This is my .htaccess: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] Someone knows how to change the .htaccess to admit .js files? @Guns @Jai @shan22 – mrroot5 Commented Apr 11, 2014 at 23:52
Add a ment  | 

4 Answers 4

Reset to default 5

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]
<script  src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>

This is the correct path.Try it!

The problem is the .htaccess provided by codeigniter to remove the index.php. Follow this link: http://www.codeigniter./userguide2/general/urls.html

Remove this code in your .htaccess and you can load javascript files :).

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

Assets folder must be outside the application folder. Like below snapshot. Then user the below code in views files to include css, js and fonts files.

Folder structure for css/js/fonts files in codeigniter

<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery-1.11.3.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>

本文标签: phpcodeigniter javascript not found errorStack Overflow