Php 为什么我在Codeigniter中仍然收到500个内部服务器错误?
请先阅读此问题,然后再尝试否决它。这个问题重复的太多了,不幸的是没有一个对我有用。 我使用的是CodeIgniter_2.1.4版本 我有一个简单的注册表,需要通过Ajax请求将其数据插入数据库。当表单中没有错误时:Php 为什么我在Codeigniter中仍然收到500个内部服务器错误?,php,ajax,codeigniter,Php,Ajax,Codeigniter,请先阅读此问题,然后再尝试否决它。这个问题重复的太多了,不幸的是没有一个对我有用。 我使用的是CodeIgniter_2.1.4版本 我有一个简单的注册表,需要通过Ajax请求将其数据插入数据库。当表单中没有错误时: POST path/index.php/controller/method 500 (Internal Server Error) 我尝试了以下解决方案,但仍然出现错误: 我已经在我的config.php文件中启用了CSFR保护:$config['csrf\u protectio
POST path/index.php/controller/method 500 (Internal Server Error)
我尝试了以下解决方案,但仍然出现错误:
config.php
文件中启用了CSFR保护:$config['csrf\u protection']=TRUE代码>
form\u open()
和form\u close()
标记,因为CI文档说明,如果使用form\u open()
,它将自动在表单中插入隐藏的csrf字段$("#sign-up").submit(function(e){
e.preventDefault();
alert($(this).serialize());
$.ajax({
method:"POST",
data:$(this).serialize(),
url:"<?php echo site_url('viewer/signup_process')?>",
success:function(data){
$("#update").html(data);
}
}) ;
});
原因可能是什么?试着改变一下
method:"POST",
到
您是否已将表单验证模块包含在
自动加载
文件中
否则,您需要在函数的第一行执行此操作:
$this->load->library('form_validation');
回答我自己的问题
我可以通过使用htaccess重写索引文件来解决这个问题
步骤
1) 创建一个.htaccess文件并将其保存在根目录中
这是.htaccess文件
public function signup_process()
{
$this->form_validation->set_rules("firstname","Firstname","required");
$this->form_validation->set_rules("lastname","Lastname","required");
$this->form_validation->set_rules("username","Username","required|max-length[10]");
$this->form_validation->set_rules("password","Password","required|min-length[5]");
$this->form_validation->set_rules("telephone","Telephone","required");
$this->form_validation->set_rules("email","email","required|valid_email");
$this->form_validation->set_rules("terms","Terms & Conditions","callback_agree_to_terms");
if(!$this->form_validation->run()){
//There are errors
$data["title"]="Errors";
$data["errors"]= validation_errors();
$this->load->view("public/errors",$data);
} else {
$viewer=array(
"firstname"=> $this->input->post("firstname"),
"lastname"=> $this->input->post("lastname"),
"username"=> $this->input->post("username"),
"password"=> $this->encrypt->sha1($this->input->post("password")),
"telephone"=> $this->input->post("telephone"),
"email"=> $this->input->post("email")
);
$create_result= $this->Viewer_model->create_viewer($viewer);
if($create_result){
$data["message"]="Registration successful..Please sing in";
$this->load->view("public/success",$data);
}
}
}
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|css|js|img|robots\.txt)
RewriteRule ^(.*)$ /project_name/index.php/$1 [L]
注释-您的css、js、img文件夹可能有不同的名称。您的文件夹可能不止这些。相应地调整它
2) 转到application->config->config.php并使
$config['index_page'] = '';
就是这样
希望这将有助于未来的读者如果您向自己的网站提出请求,请打开您的
错误报告级别,查看日志以了解错误的实际情况?如果您只是在本地测试,尝试捕捉并回显您得到的错误。@sevensacat-我在php.ini中生成了error\u reporting=E\u ALLfile@Jimmy-我在try-catch块中尝试了create语句,但在catch块中未打印任何异常。是的,我正在本地测试您的前端和后端在不同的服务器上吗?对不起。它不在自动加载文件中。但它在我的控制器的构造函数中
$config['index_page'] = '';