0

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

除非我<!DOCTYPE HTML>在 index.php 的开头声明(由 Code Igniter 提供的根目录中的文件),否则 Internet Explorer 会强制自己进入怪癖模式并完全弄乱我的页面。我试过把我的观点放在开头,但没有运气。

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

那么为什么将文档类型声明放在我的视图顶部时会被忽略?为什么它放在 index.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');
        }
    }

这是header.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>
4

1 回答 1

4

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

于 2012-05-11T09:21:54.217 回答