如何显示结果Jquery

时间:2016-05-03 02:29:03

标签: javascript jquery codeigniter

我正在尝试从jquery检索变量到我的codeigniter控制器。

我的Jquery

    $(document).ready(function () {
    $('#reservation').change(function(){
            var ids = $('#reservation').val();
            $.post ( "<?php echo base_url();?>index.php/sia/index/",
             { date_search:ids },
             function(data){
                //what i need to do ??
             });
    });
});

我的HTML

       <div class="input-group margin col-lg-3 col-xs-6 pull-right">
         <input type="text" class="form-control pull-right" readonly="readonly" placeholder="Cari Berdasarkan Tanggal" name="date_search" id="reservation" />
       </div>

这是我的控制器

     function index()
         {
           // How to retrieve date_search 
            $explode = explode('-',$date_search);
            $start_date = inggris_date($explode[0]);
            $end_date = inggris_date($explode[1]);
            $data['master'] = $this->db->query("select status,b.Nip,b.positioncode,a.start_date,a.ApprovedBy,c.OutletCode,a.Approvedby,a.IdAttendanceA,a.Alokasi,a.keterangan,a.files,b.FullName
            from Attendance_Alokasi a left join employee b on a.Nip = b.Nip
            left join outlet c on b.OutletCode = c.OutletCode
            where flag = '1' and (start_date >= '".$start_date."' and start_date <= '".$end_date."') and a.Nip = '".$Nip."'")->result();
        $data['judul'] = "Sia";
        $view = "sia/index";
        $controller = "sia";
        $this->get_view($data,$view,$controller);         
         }

如何在我的控制器中检索date_search:ids并执行echo

更新。

当我在输入alert(ids)之后05/03/2016 - 05/03/2016这里结果是: enter image description here

2 个答案:

答案 0 :(得分:1)

这个你的控制器

 function index()
     {
        $date_search = $this->input->post('date_search'); 
        $explode = explode('-',$date_search);
        $sd = trim($explode[0]);
        $ed = trim($explode[1]);
        $start_date = inggris_date($sd);
        $end_date = inggris_date($ed);
        $data['master'] = $this->db->query("select status,b.Nip,b.positioncode,a.start_date,a.ApprovedBy,c.OutletCode,a.Approvedby,a.IdAttendanceA,a.Alokasi,a.keterangan,a.files,b.FullName
        from Attendance_Alokasi a left join employee b on a.Nip = b.Nip
        left join outlet c on b.OutletCode = c.OutletCode
        where flag = '1' and (start_date >= '".$start_date."' and start_date <= '".$end_date."') and a.Nip = '".$Nip."'")->result();
    $data['judul'] = "Sia";
    $view = "sia/index";
    $controller = "sia";
    $this->get_view($data,$view,$controller);         
     }

现在在客户端。以下将提醒您输入的date_search

function(data){
  //here you data is the return value from sia/index/`
   alert(data);
});
...

答案 1 :(得分:0)

查看第一个example on jQuery网站:

$.post( "ajax/test.html", function( data ) {
    $( ".result" ).html( data );
});