我在Code Igniter中编写了一个应用程序。
除非我在index.php(Code Igniter提供的根目录中的文件)的最开头声明<!DOCTYPE HTML>
,否则Interenet Explorer会强制进入怪异模式并完全弄乱我的页面。我一直试着把我的观点放在最开始,但没有运气。
这通常不会有问题,但其中一个控制器为移动认证系统提供动力,该系统在视图中返回JSON响应,<!DOCTYPE HTML>
阻碍了响应。
那么为什么在放置在我的视图顶部时会忽略doc类型声明?为什么它放在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>
答案 0 :(得分:4)
将JavaScript打印件移除到控制台。它们不应该在视图之前运行。