简体   繁体   English

Codeigniter内部服务器错误

[英]Codeigniter Internal Server Error

I have this ajax request 我有这个ajax请求

$.ajax({
    type : 'POST',
    url : '<?php echo base_url('Home_controller/editUser'); ?>',
    data : { user_id : user_id, name : name, position : position, office : office, password : password, reports_to : reports_to, user_type : user_type, status : status },
    dataType : 'json',
    success : function(data){
        $('#name' + numberId).html(this.name);
        $('#position' + numberId).html(this.position);
        $('#office' + numberId).html(this.office);
        $('#password' + numberId).html(this.password);
        $('#reports_to' + numberId).html(this.reports_to);
        $('#user_type' + numberId).html(this.user_type);
        if(this.status == 1){
            $('#status' + numberId).html("Activated");
        }
        else if(this.status == 0){
            $('#status' + numberId).html("Deactivated");
        }

        $('#edit_user_modal').modal('toggle');
    },
    error : function(errorw){
        alert('Error');
    }
});

This is my editUser method in my Home_controller 这是我的Home_controller中的editUser方法

public function editUser(){
    $user_id = $this->input->post('user_id');
    $name = $this->input->post('name');
    $position = $this->input->post('position');
    $office = $this->input->post('office');
    $password = $this->input->post('password');
    $reports_to = $this->input->post('reports_to');
    $user_type = $this->input->post('user_type');
    $status = $this->input->post('status');

    $this->home_model->updateUser($user_id, $name, $position, $office, $password, $reports_to, $user_type, $status);

    $user_details = $this->home_model->getUserDetails($user_id);
    echo json_encode($user_details);
}

I used alert on all the values on my data and they are all correct. 我对数据中的所有值使用了alert ,它们都是正确的。 I also checked the url and it is correct. 我还检查了URL,它是正确的。 I wonder where did I go wrong? 我想知道我哪里出错了? Can someone please help me. 有人可以帮帮我吗。

This is the error jquery-2.2.1.js:9175 POST http://localhost/ppmp/Home_controller/editUser 500 (Internal Server Error) . 这是错误jquery-2.2.1.js:9175 POST http://localhost/ppmp/Home_controller/editUser 500 (Internal Server Error) I tried to open the url in the error in a new tab and yes it can be found. 我试图在新标签中的错误中打开URL,可以找到它。

I'm stuck here for hours now. 我在这里呆了几个小时。 Thanks for the help. 谢谢您的帮助。

The problem that i can se, is that in your ajax request you have: 我能解决的问题是,在您的ajax请求中您有:

$.ajax({
    type : 'POST',
    url : '<?php echo base_url('Home_controller/editUser'); ?>',
    data : { user_id : user_id, name : name, position : position, office : office, password : password, reports_to : reports_to, user_type : user_type, status : status },
    dataType : 'json',

and in your controller yo have: 并且在您的控制器中,您具有:

$user_id = $this->input->post('user_id');
    $name = $this->input->post('name');
    $position = $this->input->post('position');
    $office = $this->input->post('office');

The problem is that you send a request as a json, but you get the values as a post, you need to change the request from json to normal string. 问题是您将请求作为json发送,但是将值作为帖子发送,您需要将请求从json更改为普通字符串。

In the other hand you can get the values in you controller as a: 另一方面,您可以通过以下方式在控制器中获取值:

$values = $this->input->get_post($_GET);

$new_format = jason_decode($values);

and then proccess the result as you need 然后根据需要处理结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM