在codeigniter中使用ajax发布表单值

时间:2017-03-01 10:01:07

标签: jquery ajax codeigniter

我在我的应用程序中有一个表单...我在下一轮有一个名为schedule的按钮..当用户点击按钮我希望将表单值存储在数据库中时,页面应该只保留在那里。

这是我的表格:

<form method="post"  action="" id="form">
<b>Date </b>:<input type="text" name="date" id="date"><br><br>
<input type="hidden" name="candidate_id" value="<?php echo $getCandidate['candidate_id']; ?>">                    
<input type="hidden" name="user_id" value="<?php echo $getCandidate['user_id']; ?>">
<input type="hidden" name="req_id" value="<?php echo $getCandidate['req_id']; ?>"> 
<div class="form-group">
<label><b>Select Interview Type:</b></label>
<select  class="form-control"  id="interview_type_id" name="interview_type_id" >
<option value="" disabled selected>Interview Type</option>                                                   
<?php foreach($interviewtype as $rows) { ?>
<option value="<?php echo $rows->interview_type_id?>"><?php echo ucfirst($rows->interview_type_name)?></option>
<?php } ?>                                                    
</select>
</div><br>
<div class="form-group">
<label><b>Select Status:</b></label>
<select  class="form-control"  id="status_type_id" name="status_type_id" >
<option value="" disabled selected>Status Type</option>
<?php foreach($statustype as $rows) { ?>
<option value="<?php echo $rows->status_type_id?>"><?php echo ucfirst($rows->status)?></option>
<?php } ?>
</select>
</div><br>
<button type="submit"  name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>
<button type="submit" id="submit_enquiry" name="submit" class="btn btn-primary">Schedule Next Round</button><br></br> 
</form>

的Ajax:

<script>
$(function(){
$( "#submit_enquiry" ).click(function(event)
{
event.preventDefault();//prevent auto submit data
var date= $("#date").val();
//var last_name= $("#last_name").val();
//var dob= $("#dob").val();
//assign our rest of variables
$.ajax(
{
type:"post",
url: "<?php echo base_url(); ?>index.php/Candidate/candidate_process",//URL changed 
//data:{ date:date},
data: '{"date":"' + date+'"}',
dataType: 'json',
success:function(data)
{
console.log(data);
}
});
});
});
</script>

控制器:

function candidate_process($candidateid)

{

  $data["msg"]="";
  $id =  $this->uri->segment(3);
  $this->load->model('CandidateModel');
$data['statustype']=$this->CandidateModel->getstatustypes();
$data['interviewtype']=$this->CandidateModel->getinterviewtypes();
$data['candidate']=$this->CandidateModel->getcandidates();
$data['usertype']=$this->CandidateModel->getvendors();
$data['getCandidate'] = $this->CandidateModel->get_candidate_detail($candidateid);
$data['view_candidates'] = $this->CandidateModel->getcandidateselection($candidateid);//this is my table view

if($this->input->post('submit')=="submit")
{ 
  $this->CandidateModel->add_candidate_selection($this->input->post());
  redirect(base_url('Candidate/view_candidate_selection'));
}
 $this->load->view('Candidates/candidate_process',$data);

}

型号:

 public function add_candidate_selection($data)

{

$data=array(
     'candidate_id'=>$this->input->post('candidate_id'),
    'user_id'=>$this->input->post('user_id'),
       'req_id'=>$this->input->post('req_id'),
    'status_type_id'=>$this->input->post('status_type_id'),
    'interview_type_id'=>$this->input->post('interview_type_id'),
    'date'=>$this->input->post('date')

    );
$this->db->insert('candidate_selection', $data);
//print_r($data);

}

我试过了..但是它没有用..

任何人都可以帮助我..

提前致谢...

0 个答案:

没有答案
相关问题