猿问

如何使用codeigniter在url中传递变量?

我正在传递多个变量window.location.href="<?php echo base_url(); ?>search?result="+state1+"&c="+city1;而不是window.location.href="<?php echo base_url(); ?>search/"+state1+"/"+city1;


现在,问题是当我定义时,route即$route['search?(:any)'] = "test/search?$1";在单击“提交”按钮后,它在search页面上显示错误,什么也不打印。那么,我该如何解决这个问题?请帮我。


看法:


<script>

    $(".submit").click(function(){

        state1 = $("#state1").val();

        city1 = $(".city1").val();

        window.location.href="<?php echo base_url(); ?>search?result="+state1+"&c="+city1;

    });

</script>

控制器:


public function search($raw)

{

    echo $raw;

}

config / route.php


$route['search?(:any)'] = "test/search?$1";

谢谢你


墨色风雨
浏览 116回答 3
3回答

陪伴而非守候

您的路由错误。无需路由url即可访问$_GET值。尝试下面的代码。更改$route['search?(:any)'] = "test/search?$1";为$route['search'] = "test/search";要获得它的值:$this->input->get('result');$this->input->get('c');

繁星点点滴滴

您尝试使用Get方法值(例如Url参数),请尝试以下代码jQuery代码&nbsp; &nbsp; &nbsp;$(".submit").click(function(){&nbsp; &nbsp; state = $("#state").val();&nbsp; &nbsp; city = $(".city").val();&nbsp; &nbsp; window.location.href="<?php echo base_url(); ?>search?state="+encodeURIComponent(state)+"&city="+encodeURIComponent(city);});路线$route['search'] = "test/search";控制器public function search()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $state = $this->input->get('state');&nbsp; &nbsp; &nbsp; &nbsp; $city = $this->input->get('city');&nbsp; &nbsp; }
随时随地看视频慕课网APP
我要回答