首页 > 解决方案 > 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

这是数据库表结构 在此处输入图像描述

标签: phpajaxcodeigniter

解决方案


推荐阅读