简体   繁体   中英

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.

I want to get like this http://localhost/mvc/index.php/1/ASC in my URL.How to do that?

You can just over right the form action in onchange event by jquery.

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.

You can build the URL like this http://localhost/mvc/index.php/1/ASC by using javascript.

add below route like this (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.

$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.

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) {  

         }

   });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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