[英]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.