代码点火器文档类型


Code Igniter Doc Type

我在Code Igniter中编写了一个应用程序。

除非我在索引的最开头声明<!DOCTYPE HTML>.php(代码点火器提供的根目录中的文件),否则Interenet Explorer会强迫自己进入怪癖模式并完全搞砸我的页面。我试图把我的观点放在一开始,但没有运气。

这通常不是问题,但其中一个控制器为移动身份验证系统提供支持,该系统在视图中返回 JSON 响应,而<!DOCTYPE HTML>会阻碍响应。

那么,为什么将文档类型声明放在视图的顶部时会被忽略呢?为什么当它放在索引的顶部时会起作用.php?

更重要的是,我该如何解决这个问题?

感谢您的任何帮助!

编辑:

下面是加载视图的控制器方法的示例:

public function login()
    {
        ?><script type="text/javascript">console.log("Admin log in panel loaded");</script><?php
        //This method will have the credentials validation
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_checkDatabase');//Database gets queried with a call-back here.
        //Set custom validation messages:
        $this->form_validation->set_message('checkDatabase', 'Invalid credentials');
        //This is executed when the form is submitted
        if($this->form_validation->run() == FALSE)
        {
            //Field validation failed. User remains on login page.
            $this->load->view('header');
            $this->load->view('useradminviews/login');
            $this->load->view('footer');
        } else {
            //Login successful, redirect to admin dashboard
            ?><script type="text/javascript">console.log("User logged in successfully");</script><?php
            redirect('useradmin?login', 'refresh');
        }
    }

这是标题.php:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>COFRA</title>
<link rel="icon" type="image/png" href="<?php echo base_url();?>/images/favicon.png" />
<script type="text/javascript" src="<?php echo base_url();?>/javascript/jquery.js"></script>
<?php
//Load different CSS for IE users:
if ($this->agent->is_browser('Internet Explorer'))
{
    ?>
        <link href="<?php echo base_url();?>/javascript/placeholder/css/style.css" rel="stylesheet" type="text/css" media="screen"/>
        <link href="<?php echo base_url();?>/css/COFRAIE.css" rel="stylesheet" type="text/css" media="screen"/>
        <script type="text/javascript" src="<?php echo base_url();?>/javascript/placeholder/js/jquery.placeholder.js"></script>
    <?php
} else {
    ?><link href="<?php echo base_url();?>/css/COFRA.css" rel="stylesheet" type="text/css" media="screen"/><?php
}
?>

</head>

删除 JavaScript 打印到控制台。它们不应在视图之前运行。