如标题中所述......我无法确定我是否正确执行了后期操作,或者操作是否正确执行,那么为什么值为空,因为我在传入之前检查了该值后期操作......这是我的代码:
脚本:
$.ajax({
url: "<?php echo base_url();?>/Index/viewDayDocuments",
type: 'post',
data: {currentDay: 'currentDay', currentMonth: 'currentMonth', currentYear: 'currentYear'},
success: function(result){
$('.list').text('');
$('.list').remove();
$(".listIncoming").html("<p class = 'list'>This is the: "+ result +"</p>");
$("#myform").show(500);
}
});
控制器代码,它返回一个返回值:
$data['day'] = $_POST['currentDay'];
$data['month'] = $_POST['currentMonth'];
$data['year'] = $_POST['currentYear'];
$date = $data['year']."-".$data['month']."-".$data['day'];
$this->load->model('search_form');
$output['details'] = $this->search_form->searchDateRetrievedIncoming($date);
return $data;
答案 0 :(得分:0)
您的ajax请求需要一个以字符串形式回显的字符串。
$data['day'] = $_POST['currentDay'];
$data['month'] = $_POST['currentMonth'];
$data['year'] = $_POST['currentYear'];
$date = $data['year']."-".$data['month']."-".$data['day'];
$this->load->model('search_form');
$output['details'] = $this->search_form->searchDateRetrievedIncoming($date);
echo json_encode($data);
如果数组不是数据格式(例如JSON),则无法正确回显数组。
现在我们,在你的javascript中获取数据
$.ajax({
url: "<?php echo base_url();?>/Index/viewDayDocuments",
type: 'post',
data: {currentDay: 'currentDay', currentMonth: 'currentMonth', currentYear: 'currentYear'},
success: function(result){
$('.list').text('');
$('.list').remove();
date = JSON.parse(result);
$(".listIncoming").html("<p class = 'list'>This is the: "+ date.month +"/"+date.day+ "/"+date.year +"</p>");
$("#myform").show(500);
}
});
在这个模块中,我将STRING从PHP文件转换为JSON对象,以便正确读取。