dongyuan1970 2016-01-01 11:38
浏览 61
已采纳

无法使用带有codeigniter的ajax post jquery请求在数据库中插入数据

I want to insert row in database using ajax jquery post method for that i am using the below code in Codeigniter, but my data is not inserted in a database. Please help to sort out my issue.

View:

$("#Submit_Course_Goal").on("click", function (e) {
e.preventDefault();
var dataString = $("form#courseGoalForm").serializeArray();
alert("datastring"+dataString);
$.ajax({
    type: "post",
        url: "<?php echo base_url();?>create_course/create_course_goal",
    cache: false,               
    data: dataString,
    success: function(data){
    alert("data"+data);
    },
    error: function(){                      
    alert('Error while request..');
    }
 });
});

<form name="courseGoalForm" id="courseGoalForm" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="c_id" value="<?=$result;?>" />
<textarea data-focus="false" rows="8" name="description1"> </textarea>
<textarea data-focus="false" rows="8" name="description2">   </textarea>
<textarea data-lang="en" rows="8" name="description3">  </textarea>
<input type="submit" name="submit" value="Save" class="btn btn-primary btn btn-success" id="Submit_Course_Goal" />
</form>

Model:

public function create_course_goal($data,$id) {

   $this->load->database();
   $this->db->where('id', $id);
   $this->db->update('course', $data);
   $course_id=$id;
   if ($this->db->affected_rows() > 0) {
    return $course_id;
   }
   else
   {
   return false;
   }
}

Controller:

public function create_course_goal(){

    $course_goal1=$this->input->post('description1');
    $course_goal2=$this->input->post('description2');
    $course_goal3=$this->input->post('description3');
    $id=$this->input->post('c_id');  

    $data=array('course_goal1'=>$course_goal1,'course_goal2'=>$course_goal2,'course_goal3'=>$course_goal3);
    $result_course = $this->course_model->create_course_goal($data,$id);

    if($result_course!='false')
    {
        return true;
    }
    else
    {
        return false;
    }

}
  • 写回答

4条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 python写一下 if问题
      • ¥15 opencv c++虚拟画家
      • ¥20 python 生成exe报错问题
      • ¥30 基于香农-费诺-埃利斯编码实现对英文文本的压缩和解压缩
      • ¥15 react native ios端amap问题
      • ¥15 fortran95中5个学生分不同学号求数学语文英语计算机四门课程的每名学生的平均分以及名次以及单科成绩的平均分
      • ¥30 excel vba 执行从 1 到 100 的乘法。执行结果保存成二维数组
      • ¥15 数字电子技术基础设计实验
      • ¥15 ue5运行非常卡顿,是电脑配置原因吗
      • ¥50 有没有大佬看一下关于思科的这道题怎么做