2016-10-21 2 views
0

쿼리 결과를 필터링 할 수있는 양식이 있습니다. 그것은 단지 날짜에 기초한 필터 일뿐입니다. 어떻게 든 내 입력 값은 컨트롤러에 전송되지 않지만 콘솔에 로그를 기록하면 예상 한 값이 표시됩니다.아약스의 입력 값이 컨트롤러에 전송되지 않았습니다.

내보기 :

<form action="" method="post" id="cashback"> 
User Email : 
<input type="text" name="email" id="email"> 
<br><br> 
Booking Date : 
<div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; display:inline"> 
    <span></span> <b class="caret"></b> 
</div> 
<input type="hidden" name="input_date_from" id="input_date_from" value=""> 
<input type="hidden" name="input_date_to" id="input_date_to" value=""><br><br> 
<button type="button" class="btn btn-primary" onclick="promotion()">View</button> 
<br><br> 
</form> 
<script> 
function promotion() { 

email = $('#email').val(); 
input_date_from = $('#input_date_from').val(); 
input_date_to = $('#input_date_to').val(); 

$.ajax 
    ({ 
     url : "<?php echo site_url('admin/check_promotion')?>", 
     type: "POST", 
     dataType: "text", 
     data:{email: email, input_date_to: input_date_to, input_date_from: input_date_from}, 
     success: function(data) 
     { 
      console.log(email); 
      console.log(input_date_from); 
      console.log(input_date_to); 
      window.location.href = "<?php echo site_url('admin/check_promotion')?>"; 
     } 
    }); 
} 
</script> 

내 컨트롤러 :

public function check_promotion() 
{ 
    if(!$this->user_permission->check_permission())return; 

     $data['startDate'] = $this->input->post('input_date_from'); 
     $data['endDate'] = $this->input->post('input_date_to'); 
     $email = $this->input->post('email'); 

     $this->db->select('a.booking_id as booking_id, a.from_email as from_email, a.booking_date as booking_date, a.status as status, b.vendor_airway_bill as awb, b.tariff as tariff'); 
     $this->db->from('booking as a'); 
     $this->db->join('shipment as b','a.booking_id = b.booking_id','left'); 
     $this->db->where('booking_date >=', date('Y-m-d',strtotime($data['startDate']))); 
     $this->db->where('booking_date <=', date('Y-m-d',strtotime($data['endDate']))); 
     $this->db->where('from_email', $email); 
     $this->db->where('status = 1'); 
     $this->db->or_where('status = 2'); 
     $this->db->limit('300'); 
     $query = $this->db->get(); 
     $data['result'] = $query->result_array(); 

     $this->template->render('admin/promotion',$data,'admin'); 
} 

그것은 나에게 입력 email, input_range_toinput_range_from을 무시하고 모든 행을 제공합니다. 참고로 jQuery daterangepicker을 사용하고 있습니다. 나는 무엇을 잘못 했는가?

<script> 
function promotion() { 

    email = $('#email').val(); 
    input_date_from = $('#input_date_from').val(); 
    input_date_to = $('#input_date_to').val(); 

    $.ajax 
    ({ 
    url : "<?php echo site_url('admin/check_promotion')?>", 
    type: "POST", 
    dataType: "text", 
    data:{email: email, input_date_to: input_date_to, input_date_from: input_date_from}, 
    success: function(data){ 
     console.log(email); 
     console.log(input_date_from); 
     console.log(input_date_to); 
     window.location.href = "<?php echo site_url('admin/check_promotion')?>"; 
    } 
    }); 
    return false; 
} 
</script> 
  • 당신이 홍보 기능 전에 return을 추가해야합니다 :

  • +0

    ;'이 라인'$ 쿼리에서 = 귀하의 컨트롤러에 $ this-> db-> get();'을 입력 한 다음 여기에 쿼리를 표시하십시오 (콘솔에서 찾을 수 있습니다) –

    답변

    0

    당신은

    1. 당신은 다음과 같은 자바 스크립트 함수 promotionreturn false한다 버튼의 클릭 이벤트의 기본 동작을 피해야한다 다음과 같이 호출하십시오 :

      <button type="button" class="btn btn-primary" onclick="return promotion()">View</button> 
      

    OR : 당신은 다음과 같은 다른 솔루션을 시도 할 수 있습니다 :이`에코 $ this-> DB-> last_query() '반환을 넣어

    <form action="" method="post" id="cashback"> 
    User Email : 
    <input type="text" name="email" id="email"> 
    <br><br> 
    Booking Date : 
    <div id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; display:inline"> 
        <span></span> <b class="caret"></b> 
    </div> 
    <input type="hidden" name="input_date_from" id="input_date_from" value=""> 
    <input type="hidden" name="input_date_to" id="input_date_to" value=""><br><br> 
    <button type="button" id="btn-submit" class="btn btn-primary">View</button> 
    <br><br> 
    </form> 
    <script> 
    $('#btn-submit').click(function(e){ 
        e.preventDefault(); 
    
        email = $('#email').val(); 
        input_date_from = $('#input_date_from').val(); 
        input_date_to = $('#input_date_to').val(); 
    
        $.ajax({ 
        url : "<?php echo site_url('admin/check_promotion')?>", 
        type: "POST", 
        dataType: "text", 
        data:{email: email, input_date_to: input_date_to, input_date_from: input_date_from}, 
        success: function(data) 
        { 
         console.log(email); 
         console.log(input_date_from); 
         console.log(input_date_to); 
         window.location.href = "<?php echo site_url('admin/check_promotion')?>"; 
        } 
        }); 
    }); 
    </script> 
    
    +0

    답변을 주셔서 감사합니다. 제 질문을 편집하고 제안했지만 그래도 여전히 같은 결과. 어떻게 든, 입력 게시물의 값은 컨트롤러에 보내지는 것이 아니라 '이메일'과 날짜 범위를 무시합니다. ( – may

    0
    Following code is useful to send the data from view to controller using ajax. 
    
        <script> 
        function promotion() { 
         $.ajax 
         ({ 
         url : "<?php echo site_url('admin/check_promotion')?>", 
         type: "POST", 
         data:$('#cashback').serialize(), //$('#cashback') is the form id 
         success: function(){ 
          location.reload(); // This will refresh the page after submit or you can do whatever you want. 
         } 
         }); 
        } 
        </script> 
    
        Now, You Can get the Posted date in your controller or model using the input field name like 
    
        $email    = $this->input->post('email'); 
        $input_date_from = $this->input->post('input_date_from'); 
        $input_date_to  = $this->input->post('input_date_to'); 
    
        Thanks, 
    
    +0

    답장을 보내 주셔서 감사합니다. 양식을 제출 한 후 다른 페이지로 결과를 표시하는 더 나은 방법이 있습니까? 나는'window.location.href'를 사용하고 있습니다 :( – may

    관련 문제