php - db 行未更新
问题描述
我有这个输入复选框:
<input type="checkbox" id="224" onchange="markThisLessonAsCompleted('224');" value="1">
这个ajax调用:
function markThisLessonAsCompleted(lesson_id) {
$('#lesson_list_area').hide();
$('#lesson_list_loader').show();
var progress;
if ($('input#'+lesson_id).is(':checked')) {
progress = 1;
}else{
progress = 0;
}
console.log(progress);
$.ajax({
type : 'POST',
url : '<?php echo site_url('user/save_course_progress_new'); ?>',
data : {lesson_id : lesson_id, progress : progress},
success : function(response){
//currentProgress = response;
console.log(response + "-");
$('#lesson_list_area').show();
$('#lesson_list_loader').hide();
}
});
}
这是控制器:
function save_course_progress_new() {
$response = $this->user_model->save_course_progress_new();
echo $response;
}
这是模型:
function save_course_progress_new() {
$data['user_id'] = $this->session->userdata('user_id');
$data['lesson_id'] = $this->input->post('lesson_id');
$data['done'] = '1';
$this->db->insert('watch_history', $data);
return json_encode($data);
}
由于某种原因,db->insert 没有插入新行,ajax 也总是在控制台中输出:
(progress) 1/0
(inside the ajax response) -
我有什么遗漏吗?
1. why is the database row not added
2. why the ajax response is empty
解决方案
推荐阅读
- python - 在 strptime 中将字符视为文字
- tensorflow - Tensorflow:生成标签映射文件
- javascript - 在 Vue 中,createElement() 实际获取的参数是什么?
- android - 从共享元素转换返回后 CardView 阴影闪烁
- reactjs - 无法访问路径参数
- java - Android Studio CMake 错误:构建命令失败 fasttext
- animation - NativeScript Grid 行高调整动画
- intellij-idea - 如何撤消上次丢弃的 2 个未提交文件?
- amazon-web-services - 如何在 EMR 集群上访问此路径 /etc/hadoop/conf?
- javascript - 在 Node.js 中需要 posix cksum