简体   繁体   中英

Codeigniter ajax request not working

I send one request to controller ,And When I alert(tele) to controller it is display values,But in controller it shows empty,,

But Other date1 and date2 are working..

<script type="text/javascript">
$(document).ready(function(){
$('#buttonsearch').click(function(){
var date1=$("#date1").val(); 
var date2=$("#date2").val();vartele=$("#tele").val();
 alert(tele);
 $.ajax(
 {
 type: "POST",
 url: '<?php echo site_url('totalorders/orderajax'); ?>',
 data: 'date1=' + date1 + '&date2='+ date2 +'& tele ='+ tele,
 success: function(data)
 {
 alert(data);
 $("#customers2").html(data);
 }}); });});
</script>

controller code..

 public function orderajax()
    {

         $this->load->database();
        $this->load->library('session');
        $date1=$this->input->post('date1');
        $date2=$this->input->post('date2');
        $tele=$this->input->post('tele');
        $data['tele']=$tele;
        if(($date1 != '') && ($date2 != '') && ($tele == ''))
        {

            $data['orders'] = $this->orderdetails->get_ajaxsearchorders($date1,$date2,$tele);
        }
        else 
        {
            $sss=$tele;
            $data['orders'] = $this->orderdetails->get_ajaxsearchorders1($sss);
        }
        $this->load->view('orderviewajax',$data);
    }

can you guys help me where i was wrong..

Note : only 'tele' value is not working date1,date2 are working..

Give the space between the key word var and the variable name tele. Check the following line.

var tele = $("#tele").val();

add space in variable declaration. and while posting data dont give a space. For Eg:

             type:"POST",
             url:"<?php echo base_url(); ?>staff_activity/date_report",
             data:'year='+nep_year+'&month='+nep_month,

Your root problem is the space you've embedded within the query string in this part:

... +'& tele ='+ tele

Remove the space between & and tele ...

... +'&tele ='+ tele

HOWEVER, you don't need to collect each value and manually construct a query string.

Simply use jQuery .serialize() , which collects the form's values and constructs the query string automatically.

data:  $('form').serialize(),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM