In this example, we will show how to remove query string from URL in Codeigniter using jquery. I explain step by step to you to remove query string from URL. I will remove the query string from the URL using jquery. After reading this post you can easily remove the Codeigniter query string from the URL using jquery.

In this example, we provide jquery to remove query string from URL in Codeigniter. so let’s go following this example.


Example 

Step 1 : Create controller

In this step we will create Welcome controller for remove query sting from url. so let’s following code

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
    public function demo(){
        $_SESSION['data'] = $_GET;  
        $this->load->view("welcome");
    }
}


Step 2 : Create view

In this step we will create welcome view and display query string data.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>how to remove query string from url in codeigniter</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    </head>
    <body>

        <div class="container">
            <?= $this->session->userdata('name'); ?>
            <br>
            <?= $this->session->userdata('pwd'); ?>
        </div>

    </body>
    <script>
        $(document).ready(function() {
            var uri = window.location.toString();
            if (uri.indexOf("?") > 0) {
                var clean_uri = uri.substring(0, uri.indexOf("?"));
                window.history.replaceState({}, null, clean_uri);
            }
        });
    </script>
</html>


I hope you understand of remove query string from url using jquery and can help you..