【发布时间】:2018-11-19 06:18:26
【问题描述】:
我有两个单选按钮和一个复选框。单选按钮全部选中,当全部选中时,我必须加载一个视图页面,如果选中一个复选框,我想执行不同的操作,我必须加载不同的查看页面..我用 if 和 else 语句尝试了它,但它没有给我预期的结果..所以我用不同的函数名称尝试了它..如果选中了一个复选框,我必须在 Receipt Reg chek 上进行调用( )..我用 ajax 尝试过,但我没有收到对 Receipt Reg check() 的调用,它仍然调用在表单操作中加载的 Receipt Reg Check1() ..我的代码需要做哪些更改..帮我解决这个问题
控制器代码:
public function Receipt_reg_check1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$item=$this->input->post('item');
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}}
public function Receipt_reg_check()
{
if($this->input->post('all'))
{
if($this->input->post('item')){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
}}
HTML页面:
<form class="form-horizontal" action="<?=site_url('welcome/Receipt_reg_check1')?>" method="POST" target="_blank">
<input type="radio" class='rd'name="all" value="op1" checked=""> All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" id="AcNo" >Item description
Ajax 代码:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>welcome/Receipt_reg_check",
data:{id:$(this).val()},
datatype:'json',
success: function (data) {
var res = jQuery.parseJSON(data);
$("#AcNo").val(res);
}
});
});
</script>
【问题讨论】:
-
从您在这里写的内容看来,您的表单似乎没有连接到 AJAX 调用。您应该将 ajax 调用连接到未准备好文档的用户交互(表单按钮单击或提交)。
标签: ajax codeigniter