Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在控制器或模型中获取ajax调用提交表单的输入_Php_Ajax_Codeigniter - Fatal编程技术网

Php 无法在控制器或模型中获取ajax调用提交表单的输入

Php 无法在控制器或模型中获取ajax调用提交表单的输入,php,ajax,codeigniter,Php,Ajax,Codeigniter,我有一个关于表单提交的ajax调用;如果我在硬编码时传递sql参数,效果会很好,但是如果我想在模型中传递带有输入(来自视图)的sql查询参数,它会显示:Message:Undefined index:startDate和endDate 以下是我的看法: <?PHP $formData2 = array( 'class' => 'form-horizontal',

我有一个关于表单提交的ajax调用;如果我在硬编码时传递sql参数,效果会很好,但是如果我想在模型中传递带有输入(来自视图)的sql查询参数,它会显示:Message:Undefined index:startDate和endDate

以下是我的看法:

            <?PHP
                 $formData2 = array(
                    'class' => 'form-horizontal',
                     'id' => 'frm2',
                   );
                  echo form_open('gallery/fetchAssociates', $formData2);
            ?>
            <input id="startDate" class="span2" size="16" type="text"  />
            <input id="endDate" class="span2" size="16" type="text"  />                                 
            <input type="submit" class="btn btn-primary" 
             value="Submit" id="querystartEnd" name="querystartEnd" />                 
            <?PHP
            echo form_close();
            ?>
我的建模方法如下:

       $.ajax({
            type: "POST",
            async: false,
            dataType: "json",
?>",
            url: "<?php echo base_url('gallery/fetchAssociates') ?>",

            success: function(data) {

                html = "<table id='myTable'><thead><tr id='test'><th>ID</th><th>Start Date</th><th> LName</th></tr></thead><tbody id='contentTable'>";

                for (var i = 0; i < data.length; i++)
                {
                    html = html + "<tr  id='trResponses' ><td><div >" + data[i]['id']
                                + " </div></td><td><div >" + data[i]['start'] + 
                                   "</div> </td><td><div >" + data[i]['username'] +
                                    "</div></td></tr>";
                  }
                  html = html + "</tbody></table>";
                  $("#resultFrm2").html(html);
               },
              error: function() 
               {
                   alert('error');
               }

             });
public function getAll() 
{
    $wtc = $this->load->database('wtc', TRUE);
    $sql = "SELECT username, MIN(timeIn) as start
             FROM tc_timecard
             GROUP BY userid  having  MIN(timeIn) > ? and MIN(timeIN) < ? 
             order by MiN(timeIN);";

     //$q = $wtc->query($sql, array('2013-01-08', '2013-01-23'));
     $q = $wtc->query($sql, array($this->input->post('startDate'),
      $this->input->post('endDate')));

     if ($q->num_rows() > 0) 
        {
            foreach ($q->result() as $row) 
            {
                $data[] = $row;
             }

             return $data;
         }
 }
在firebug中未加注释的响应是“消息:未定义的索引:startDate和endDate。” 也在我的控制器中,如果我有

//        $q = $wtc->query($sql, array('2013-01-08', '2013-01-23'));
un注释它可以工作,但一旦我想通过以下代码行传递输入,它就不工作了:

$q=$wtc->query($sql,数组($this->input->post('startDate'),$this->input->post('endDate'))

我无法访问控制器或模型中的输入的原因是什么

如果您不清楚,请让我知道您需要更多澄清的部分

编辑: 值得一提的是,我的ajax调用位于以下块中:

  $('#frm2').submit(function(e) 
     {
            e.preventDefault();
            //My AJAX call here
     });

首先非常感谢,

您没有通过ajax传递任何数据

// Collect data from form which will be passed to controller
var data = {
 start_data : $('#startDate').val(),
 start_data : $('#endDate').val(),
}

$.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        data : data // data here
        url: "<?php echo base_url('gallery/fetchAssociates') ?>",
        success : function(data){
         // Success code here
        },
        error: function(data){
         // error code here
        }
})
//从表单收集数据,并将其传递给控制器
风险值数据={
开始数据:$('#开始日期').val(),
开始数据:$('#结束日期').val(),
}
$.ajax({
类型:“POST”,
async:false,
数据类型:“json”,
data:data//data在这里
url:“”,
成功:功能(数据){
//这里是成功代码
},
错误:函数(数据){
//这里有错误代码
}
})
  $('#frm2').submit(function(e) 
     {
            e.preventDefault();
            //My AJAX call here
     });
// Collect data from form which will be passed to controller
var data = {
 start_data : $('#startDate').val(),
 start_data : $('#endDate').val(),
}

$.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        data : data // data here
        url: "<?php echo base_url('gallery/fetchAssociates') ?>",
        success : function(data){
         // Success code here
        },
        error: function(data){
         // error code here
        }
})