我必须使用codeigniter将json数据插入数据库。但我有一些插入问题。
控制器
$other_details=array($last_gradel,$years_studied,$school_name,$school_town,$school_district,$school_state,$school_country,
$school_tel_no,$school_mob_no,$school_email,$third_lang,$outstanding_achieve);
$application_insert = $this->career->insert_student_application($other_details);
$status['result'] = "ok";
echo json_encode($status);
模型
function insert_student_application($other_details)
{
$data_insert = array(
'applicant_prev_grade' => $other_details[0],
'years_last_school' => $other_details[1],
'school_name' => $other_details[2],
'school_town' => $other_details[3],
'school_district' => $other_details[4],
'school_state' => $other_details[5],
'school_country' => $other_details[6],
'school_tel_number' => $other_details[7],
'school_mob_number' => $other_details[8],
'school_email_id' => $other_details[9],
'third_language' => $other_details[10],
'outstanding_achieve' => $other_details[11],
'applicant_status' => 1,
);
$this->db->insert('student_application', $data_insert);
return $this->db->last_query();
}
** ajax *(以js为单位)
$.ajax({
url: base_url+"admission/career_submit/",
data: $('#career_submit_form').serialize(),//returns all cells' data
dataType: 'json',
type: 'POST',
success: function (res) {
// alert(res.result);
if (res.result === 'ok') {
window.scrollTo(0,0);
$("#succs_msg").css("display", "block"),
window.setTimeout(function() {
location.href=base_url+'admission' ;
}, 500);
}
else {
alert("failed to save.Please Retry")
}
},
error: function (e) {
alert("function error")
location.href=base_url+'admission' ;
}
});
我在ajax函数之前获得了序列化数据。
现在我在ajax中收到错误函数错误。我在控制器中注释我的插入选项,然后显示成功消息。但我没有得到错误。