我已经用谷歌搜索并尝试了许多对其他人有效但对我无效的解决方案。我不知道为什么。
背景:
我正在学习使用 CodeIgniter 2.2.0。我已经设置了元素结构和以下所有内容,但我仍然无法加载我的 CSS 和 JS。
查看代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title> </title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<!-- solution 1 I have tried: -->
<!-- in below line I tried by using constant set in constants.php file under application/config/ folder -->
<link rel="stylesheet" href="<?php echo (CSS.'dialog.css' );?>" type="text/css">
<!-- solution 2 I have tried: -->
<!-- As my css n script files are under CodeIgniter_2.2.0/assets/css and CodeIgniter_2.2.0/assets/scripts folder respectively -->
<link rel="stylesheet" href="/assets/css/dialog.css" type="text/css">
<!-- solution 3 I have tried -->
<!-- This I tried by using autoload.php settings where I am setting autoload['helper'] = array('url'); -->
<?php echo link_tag('assets/css/dailog.css');?> </br>
<script src="../../script/Plugins/jquery.js" type="text/javascript"></script>
</head>
</html>
配置:
我也设置了
$config['base_url'] = "http://localhost/";
在 application/config/config.php
文件中。
元素文件夹结构:
我的元素文件夹结构如下:
(Application、System、Assets文件夹在同一层)
.htaccess
文件的内容是:
(.htaccess 文件路径:C:\xampp\htdocs.htaccess )
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
C:\xampp\htdocs\CodeIgniter_2.2.0\System
和 C:\xampp\htdocs\CodeIgniter_2 还有 2 个
文件夹
两者都有单行写:.htaccess
文件。 2.0\application
Deny from all
此外,在 C:\xampp\htdocs\
中,有一个文件 index.php
与 index.php
相同文件放在
C:\xampp\htdocs\CodeIgniter_2.2.0\
我在其中设置了以下内容
$system_path = 'CodeIgniter_2.2.0/system';
$application_folder = 'CodeIgniter_2.2.0/application';
我在这方面有什么遗漏吗?我无法在我的页面上加载任何 CSS 或 JS 文件。
最佳答案
这是解决方案:只需在根目录的 .htaccess
中进行更改
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
n 它的工作。 :)
关于javascript - 为什么 CSS 和 JS 没有加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26410422/