【问题标题】:Code Igniter Doc TypeCodeigniter 文档类型
【发布时间】:2012-05-11 17:21:54
【问题描述】:

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

除非我在 index.php(由 Code Igniter 提供的根目录中的文件)的开头声明 <!DOCTYPE HTML>,否则 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>

【问题讨论】:

  • 你能显示加载视图的代码的相关部分吗?
  • 嘿,当然,请看我的编辑,包括代码

标签: php html css codeigniter doctype


【解决方案1】:

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

【讨论】:

  • 哦,我的话,好像这就是问题所在!非常感谢。你怎么知道的?
  • 不客气。您不应该在 DOCTYPE 之前发送任何输出。 IE 不能很好地处理这些情况。
猜你喜欢
  • 1970-01-01
  • 2014-12-30
  • 2012-08-10
  • 2012-02-22
  • 2011-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-14
相关资源
最近更新 更多