如何使用Ajax调用控制器功能

时间:2018-11-19 06:18:27

标签: ajax codeigniter

我有两个单选按钮和一个复选框。选中所有复选框时,单选按钮全部选中,我必须加载一个视图页面,如果选中了复选框,我想执行不同的操作,并且必须加载不同的选项查看页面..我尝试了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>

1 个答案:

答案 0 :(得分:0)

放入

& 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' `
--headless --disable-gpu --screenshot=D:\Html\screenshot.png `
file:///D:/Html/New.html

代替

        $this->load->view('Receipt_View',$data);