如何确定ajax的URL

如何确定ajax的URL,ajax,codeigniter,Ajax,Codeigniter,正如标题中所述……我很难确定我是否实际正确执行post操作,或者操作是否正确执行,那么为什么该值为空,因为我在post操作中传递该值之前检查了该值……以下是我的代码: 脚本: $.ajax({ url: "<?php echo base_url();?>/Index/viewDayDocuments", type: 'post', data: {currentDay: 'currentDay', currentMonth: 'currentMonth', cu

正如标题中所述……我很难确定我是否实际正确执行post操作,或者操作是否正确执行,那么为什么该值为空,因为我在post操作中传递该值之前检查了该值……以下是我的代码:

脚本:

$.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);
    }
 });

您的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);
  } 
 });
$.ajax({
url:“/Index/viewDayDocuments”,
键入:“post”,
数据:{currentDay:'currentDay',currentMonth:'currentMonth',currentYear:'currentYear'},
成功:功能(结果){
$('.list')。文本('');
$('.list').remove();
date=JSON.parse(结果);
$(“.listIncoming”).html(“

这是:“+date.month+”/“+date.day+”/“+date.year+”

”); 元("我的表格).show(500元);; } });

在本模块中,我将PHP文件中的字符串转换为JSON对象,以便正确读取。

我尝试了您的建议,但似乎没有发生任何事情,尽管我认为……您是否认为这可能是URL?好的,这确实是一个URL问题……不知道为什么,但我将URL从以下内容更改为:“/Index/viewDayDocuments”:“viewDayDocuments”噢,我忘了告诉你。不建议将base_url()或任何其他函数回送到脚本。你应该使用JQuery中的$.ajaxPrefilter()。因此,如果你移植到其他服务器,你只需要更改一个url参数。
$.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);
  } 
 });