我试图用ajax提交表单,但它始终传递给fail
消息。 我是新来的ajax,帮我解决这个错误。Codeigniter:提交表单而不刷新ajax
这里是我的控制器:
public function add_personal() {
$id = $this->uri->segment(3);
$jid = $this->Jsprofile->get_jsid($id)->jobseeker_id;
$data = array(
'js_personal_title' => $this->input->post('js_personal_title'),
'js_personal_desc' => $this->input->post('js_personal_desc'),
'tbl_jobseeker_jobseeker_id' => $jid,
'tbl_jobseeker_tbl_user_u_id'=>$id
);
// echo json_encode($data);
$this->load->database();
$this->db->insert('tbl_js_personal',$data);
}
这是我的观点:
<form action="" method="POST" id="personal-info" class="form-group">
<input class="form-control" type="text" name="js_personal_title">
<input class="form-control" type="text" name="js_personal_desc">
<input id="submit-p" class="form-control" type="submit" value="Add">
</form>
JS:
$(document).ready(function(){
$("#personal-info").submit(function(e){
e.preventDefault();
var data= $("#personal-info").serializeArray();
$.ajax({
type: "POST",
url: 'http://localhost/joblk.com/index.php/jobseeker/add_personal',
data: data,
success:function(data) {
alert('SUCCESS!!');
},
error: function (XHR, status, response) {
alert('fail');
}
});
});
});
为获取值型号:
public function get_jsid($id) {
$sql = "SELECT jobseeker_id FROM tbl_jobseeker WHERE tbl_user_u_id = ".$id.";";
return $this->db->query($sql)->row();
}
你没得到错误? – guradio
请检查您的浏览器控制台是否有错误。 –
你没有将'jobseeker_id'传递到你的ajax url'url:'http:// localhost/joblk.com/index.php/jobseeker/add_personal',' –