[英]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.. 但是其他date1和date2正常工作。
<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.. 注意:只有'tele'值不起作用date1,date2起作用。
Give the space between the key word var and the variable name tele. 在关键字var和变量名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 ='+ 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. 只需使用jQuery
.serialize()
收集表单的值并自动构造查询字符串。
data: $('form').serialize(),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.