简体   繁体   English

我想在 URL http://localhost/mvc/index.php/1/ASC 中像这样传递参数。怎么做?

[英]I want to get parameter passed like this in URL http://localhost/mvc/index.php/1/ASC .How to do that?

My code snippet is我的代码片段是

        <form>
          <input type="hidden" name="pageno" value="<?php echo $pno;?>">
          <select name="sort" class="float-right ralign" onchange="this.form.submit()">
            <option value="" disabled selected>--select sort--</option>
            <option value="ASC">Sort by Ascending</option>
            <option value="DESC">Sort by Descending</option>
          </select>
        </form>

Currently I'm getting redirected onchange in http://localhost/mvc/index.php?pageno=1&sort=ASC format.目前,我正在以http://localhost/mvc/index.php?pageno=1&sort=ASC格式重定向 onchange。

I want to get like this http://localhost/mvc/index.php/1/ASC in my URL.How to do that?我想在我的 URL 中得到这样的http://localhost/mvc/index.php/1/ASC 。该怎么做?

You can just over right the form action in onchange event by jquery.您可以通过 jquery 直接覆盖 onchange 事件中的表单操作。

So when user choose from drop down the you need to call/create onchnage method and In this method you just over right the form action as you want because In this case you already have such parameters which you have to use in your new url.因此,当用户从下拉列表中选择时,您需要调用/创建 onchnage 方法,并且在该方法中,您可以根据需要右击表单操作,因为在这种情况下,您已经拥有必须在新 url 中使用的参数。

You can build the URL like this http://localhost/mvc/index.php/1/ASC by using javascript.您可以使用 javascript 构建这样的 URL http://localhost/mvc/index.php/1/ASC

add below route like this (application/config/routes.php)像这样添加以下路线(application/config/routes.php)

Example:例子:

$route['product/(:num)/(:num)'] = 'catalog/product_lookup_by_id/$1/$2';

You can get the values by using uri segment.您可以使用 uri 段获取值。

$this->uri->segment(1); // controller
$this->uri->segment(2); // action
$this->uri->segment(3); // 1stsegment
$this->uri->segment(4); // 2ndsegment

You can Call Ajax Onchange event of selectbox.您可以调用选择框的 Ajax Onchange 事件。

HTML HTML

<form method="post" id="frmsubmit">
          <input type="hidden" name="pageno" value="<?php echo $pno;?>">
          <select name="sort" class="float-right ralign" id="ralign">
            <option value="" disabled selected>--select sort--</option>
            <option value="ASC">Sort by Ascending</option>
            <option value="DESC">Sort by Descending</option>
          </select>
        </form>

AJAX阿贾克斯

$(document).on('change','#ralign',function(){
   var formdata = new FormData($("#frmsubmit")[0]);
   $.ajax({
         url: 'yoururl', //like insert.php or other route
         type: 'POST',
         data: formdata,
         dataType: "json",
         contentType: false,
         cache: false,
         processData: false,
         success: function(response) {  

         }

   });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM