我尝试使用jquery ajax提交表单,但我无法在控制器中获取表单值。
AJAX
$("#fdate").on("click",function(){
var controller_function= "<?php echo base_url();?>index.php/partnerdata/partnerdata/update_partnerdata_followup_date";
var post_data = $("#form").serialize();
$.ajax({
type:"post",
url:controller_function,
data:post_data,
success:function(data)
{
alert(post_data);
}
});
});
控制器
public function update_partnerdata_followup_date()
{
$this->menufunctions->loginchecking();
$data['msg'] = '';
$msg = "";
$status = 0;
$err_flag = 0;
$status_arr = array();
$eco_compr_arr = array();
$ecoid = 0;
$subeco_id = 0;
$val_eco_id = "";
$val_sub_eco_id = "";
$subecoid = "";
$check_id = $this->input->post('hidsubmit');
$fromtype = $this->input->post('fromtype');
$datee = $this->input->post('hddate');
$pageNum = $this->input->post('pageNum');
$inputdata['followup_date'] = $this->input->post('followup_date');
$inputdata['remarks'] = $this->input->post('remarks');
$inputdata['val_modified_by'] =$this->session->userdata('user_id');
$inputdata['val_modified_on'] = date("Y-m-d H:i:s");
$inputdata['hid_check_id']= $check_id;
$update = $this->partnerdata_model->update_db_row_date($inputdata);
if($update==1){
$msg = 'Updated Successfully';
$this->session->set_flashdata('msg', $msg);
}
redirect('partnerdata/partnerdata/view_partnerdata_calender/'.$datee);
}
答案 0 :(得分:1)
$("#fdate").submit(function(event) {
event.preventDefault();
var hidsubmit = $("input#hidsubmit").val();
var fromtype = $("input#fromtype").val();
var hddate = $("input#hddate").val();
jQuery.ajax({
``type: "POST",
url: "<?php echo base_url('index.php/partnerdata/partnerdata/update_partnerdata_followup_date');?>",
dataType: 'json',
data: {hidsubmit: hidsubmit, fromtype: fromtype,hddate:hddate},
success: function() {
//do alert
}
});
});
});
//Controller-----
public function update_partnerdata_followup_date()
{
$data=array(
'hidsubmit'=>$this->input->post('hidsubmit'),
'fromtype'=>$this->input->post('fromtype'),
'hddate'=>$this->input->post('hddate')
);
$this->partnerdata_model->update_db_row_date($data);
}
//这应该也可以共享您的模型 //也检查网址它似乎不对,它有重复的名称