Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我在Codeigniter中仍然收到500个内部服务器错误?_Php_Ajax_Codeigniter - Fatal编程技术网

Php 为什么我在Codeigniter中仍然收到500个内部服务器错误?

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

请先阅读此问题,然后再尝试否决它。这个问题重复的太多了,不幸的是没有一个对我有用。

我使用的是CodeIgniter_2.1.4版本

我有一个简单的注册表,需要通过Ajax请求将其数据插入数据库。当表单中没有错误时:

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字段
  • Javascript

    $("#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'] = '';