Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
Javascript 如何将Ajax URL中的两个变量传递给codeigniter控制器?_Javascript_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Javascript 如何将Ajax URL中的两个变量传递给codeigniter控制器?

Javascript 如何将Ajax URL中的两个变量传递给codeigniter控制器?,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我正在研究一个学校管理系统。我只是根据他们的班级和部门创建获取学生详细信息。我使用ajax+codeigniter控制器,但我无法在ajax调用中传递两个变量来执行2参数搜索 我的Ajax代码 查看此图,然后您就可以了解我要做什么了在您的情况下,您可以在参数中传递2个值,如下所示: echo '<pre>'; print_r($_POST); 您可以使用$\u POST将它们放入控制器中 但在您的示例中,您只发送了1个参数,而没有在控制器中获取它,您正在使用URL slug获取类

我正在研究一个学校管理系统。我只是根据他们的班级和部门创建获取学生详细信息。我使用ajax+codeigniter控制器,但我无法在ajax调用中传递两个变量来执行2参数搜索

我的Ajax代码


查看此图,然后您就可以了解我要做什么了

在您的情况下,您可以在参数中传递2个值,如下所示:

echo '<pre>';
print_r($_POST);
您可以使用$\u POST将它们放入控制器中

但在您的示例中,您只发送了1个参数,而没有在控制器中获取它,您正在使用URL slug获取类

在控制器文件中,您可以简单地在$\u POST中获取值,您可以使用以下方法检查这两个值:

data: 'class='+xclass+'&section='+section, // here you can use quote and & for separation.

在您的情况下,可以在参数中传递2个值,如下所示:

echo '<pre>';
print_r($_POST);
您可以使用$\u POST将它们放入控制器中

但在您的示例中,您只发送了1个参数,而没有在控制器中获取它,您正在使用URL slug获取类

在控制器文件中,您可以简单地在$\u POST中获取值,您可以使用以下方法检查这两个值:

data: 'class='+xclass+'&section='+section, // here you can use quote and & for separation.
试试这个

试试这个


您想传入URL还是作为POST值?先生,我想传入Ajax URL中的两个变量,如URL:acmission/fetchStudent/+xclass,您只发送1个参数数据:{'xclass':xclass}并且您在控制器中也没有使用此值,我想您使用的是URL中的slug。先生,我还使用了{'xclass':xclass',section':section}但是我用{xclass:xclass,section:section}测试失败了。您想传入URL还是作为一个POST值?先生,我想在Ajax URL中传递两个变量,比如URL:acmission/fetchStudent/+xclass,您只发送了1个参数数据:{xclass':xclass},并且您的控制器中没有使用这个值,先生,我也曾使用过{'xclass':xclass,'section':section},但是我用{xclass:xclass,section:section}@B失败了。点击左边的勾号。@B.Dontos:太好了,别忘了接受答案,这对以后会有帮助。点击左边的勾号。$\u POST'xclass'这会产生问题,我想,检查其他答案。很好,但OP现在消失了,但我给你投票支持你的努力:$\u POST'xclass'这会产生问题,我想,检查其他答案。很好,但OP现在消失了,但我给你投票支持你的努力:
echo '<pre>';
print_r($_POST);
data: 'class='+xclass+'&section='+section, // here you can use quote and & for separation.
$.ajax({
      url: "<?php echo base_url(); ?>Admission/fetchStudent/",
      type: "POST",
      data: ({xclass: xclass, section:section}),//changes
      datatype: 'json',
      success: function (data) {
             $("#resultlist").html(data);
      }
 });
public function fetchStudent(){//changes
    $this->load->model('Admission_model');
    $class  = $this->input->post('xclass');//changes
    $section  = $this->input->post('section');//changes
    $data = $this->Admission_model->fetchStudentmodel($class,$section);
    echo '<pre>';
    print_r($data);
    exit();
    echo json_encode($data);
}