douou5933 2013-03-22 11:58
浏览 48

外部js&css没有加载到codeigniter中

To load external Javascript file in codeignitor, I'm using

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

I can see in the page's source as

<script src="http://localhost/cinifb_ci/application/js/contentslider.js" type="text/javascript"></script>

which means to my knowledge that the file is loading perfectly similarly for my CSS file, I've used

<link rel="stylesheet" href="<?php echo base_url(); ?>application/css/default.css" type="text/css" />

and in the page's source code its showing as

<link rel="stylesheet" href="http://localhost/cinifb_ci/application/css/default.css" type="text/css" />

which means even its loading perfectly. (on clicking the external js/css link in the source its showing 403 Forbidden). But neither of their effects are applied on the page. No error its showing. I've loaded URL helper in controller as $this->load->helper('url');

and placed $autoload['helper'] = array('url'); in autoload.php

can you please explain me where I went wrong.

I learn that to load external JS, we need to install jquery-codeigniter library. I've downloaded them and included the respective files into respective similar folders of my application folder.

Now when I try to include $this->load->library('jquery'); in my controller, its showing

An Error Was Encountered

Unable to load the requested class: jquery

Hence I request you to please help me to understand why 403 Forbidden is showing when I can see its pointing to the exact location of the JS/CSS file and secondly if the installation of the jquery-codeigniter library is wrong please guide me.
Note: http://ellislab.com/codeigniter/user-guide/libraries/javascript.html didn't help me

Edit:
jquery-codeigniter library i've placed in system/libraries/javascript/

In systems .htaccess file, I've written as

RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php|images|css|js|video_files|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /cinifb_ci/index.php/$1 [L]

In the view I'm writing as

$this->load->helper('url');
<script src="<?php echo base_url("application/js/jquery-1.8.2.js"); ?>" type="text/javascript"></script>

In controller as

$this->load->helper('url');
$this->load->library('javascript');
$this->load->library('javascript/jquery');
$this->load->library('Jquery_ext');

again if I look at source its pointing to correct source but still if i click external js file link, its showing 403 Forbidden error
Sorry for lengthy post :(
Suggestions please ..!

  • 写回答

3条回答 默认 最新

  • dshp9580656 2013-03-22 12:14
    关注

    A 403 hidden error means that the Web Server is rejecting the request to that particular resource.

    I am going to assume you are using the provided .htaccess file to get pretty urls.

    In the line that

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

    Make it read

    RewriteCond $1 !^(index\.php|images|robots\.txt|application/js|application/css)
    

    Actually, the above could be wrong, regardless, the idea is there that you need to add your css and js folders to the RewriteCond exception list

    评论

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题