简体   繁体   English

为什么会出现500 Internal Server Error?

[英]Why am I getting a 500 Internal Server Error?

I'm learning so far, but this db ajax communication always makes me bang my head against the wall. 到目前为止,我正在学习,但是这种db ajax通信始终使我无法自拔。

This is the controller: 这是控制器:

function become_teacher()
{   
    $this->load->model('class_model');
    $data = array('user_id' => $this->input->post('user_id'),
        'group_id' => $this->input->post('user_group') 
    );
    $this->class_model->change_to_teacher($data);
}

Here is the Model: 这是模型:

function change_to_teacher($data)
{
    $this->db->insert('user_groups', $data);
    return;     
}

And here is the script: 这是脚本:

<p>Om du vill kunna skapa lektionen bli lärare. </p>
<button class="btn teacher">Bli lärare</button>

<script type="text/javascript">
    var user_id = $('.meta').text().trim();
    var user_group = '4';
    $('.teacher').on('click', function() {
        $.ajax({
            type: "POST",
            url: "http://localhost:8888/testing/index.php/cours/become_teacher",
            data: "{ user_id: user_id, user_group: user_group }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
        });
    });
</script>

The var user_id is getting its data from the header file, not included here. var user_id从头文件获取数据,此处不包括。 Any help would be much appreciated! 任何帮助将非常感激!

Don't know the detail, but 不知道细节,但是

data: "{ user_id: user_id, user_group: user_group}",

Should be 应该

data: { "user_id": user_id, "user_group": user_group},

I've missed a letter when defining the table. 定义表格时我错过了一封信。 Now its working... 现在工作了...

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

相关问题 为什么我会收到这个 500 内部服务器错误 - Why am I getting this 500-Internal Server Error 我收到500个内部服务器错误htaccess - I am getting 500 internal server error htaccess 为什么使用Zend Framework 1发送电子邮件时出现500 Internal Server Error? - Why I am getting 500 Internal Server Error while sending an email using Zend Framework 1? 我正在使用jQuery发布php文件,我正在获取500个内部服务器文件,为什么? - I am using jQuery to post a php file, I am getting 500 internal server file, Why? 为什么我在共享的免费服务器上收到这个奇怪的 500 错误 - Why i am getting this weird 500 error on a shared free server 为什么在Laravel Framework中出现此内部服务器错误? - Why am I getting this Internal Server Error in the Laravel Framework? 为什么我会收到 HTTP 500 错误? - Why am I getting a HTTP 500 error? 使用axios发出发布请求时,为什么会出现500服务器错误? - Why am I getting 500 server error when making post request with axios? 使用.htaccess获取500内部服务器错误 - using .htaccess getting 500 internal server error 在Foursquare应用上获取500个内部服务器错误 - Getting 500 internal server error on Foursquare app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM