As stated in the title...I am having trouble determining whether I'm actually performing the post operation properly or if the operation is properly performed then why is the value empty since I checked the value before passing it in the post operation...here is my code:

script:

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

controller code which throws back a return value:

    $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;
有帮助吗?

解决方案

Your ajax request needs a string echoed as a string.

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

An array cannot be echoed out correctly if it's not in a data format, such as JSON.

Now we, take the data in your 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);
  } 
 });

In this module, I transformed the STRING from your PHP file into a JSON object so it can be read properly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top