简体   繁体   中英

How can i remove parameters from url?

I have this code:

   <div id='op_name_config' style='display: none;'>
     <form action='config.html' method='get'>
        <input type='hidden' id='type_op_name' name='type' value='op_name'>
        <table align='center'>
           <tr>
              <td align='right' style='width: 1000px'>
                 <label style='width: 200px'>Grynųjų pinigų įnešimas</label>
                 <input type='text' id='op_name_idejimas' name='op_name_idejimas'>
                 <br>
                 <label style='width: 200px'>Grynųjų pinigų išėmimas</label>
                 <input type='text' id='op_name_isemimas' name='op_name_idejimas'>
                 <br>
                 <label style='width: 200px'>Grąžinimas</label>
                 <input type='text' id='op_name_grazinimas' name='op_name_grazinimas'>
                 <br>
                 <label style='width: 200px'>Avansinis mokėjimas</label>
                 <input type='password' id='op_name_avansinis' name='op_name_avansinis'>
                 <br>
              </td>
              <td style='width: 300px'></td>
           </tr>
        </table>
        <div id='Login8' style='display: none;'>
           <table align='center'>
              <tr>
                 <td width='200' align='center'>
                    <button class='btn config' type="submit" id='btn_confirm8' onclick='reloadAsGet()' >Patvirtinti</button>
                 </td>
              </tr>
           </table>
     </form>
  </div>

And when I submit i have very long url: http://127.0.0.1:3000/config.html?type=op_name&op_name_idejimas=44&op_name_idejimas=4&op_name_grazinimas=&op_name_avansinis=3

How can I hide everything after "?":type=op_name&op_name_idejimas=44&op_name_idejimas=4&op_name_grazinimas=&op_name_avansinis=3

I'm pretty new in programming, maybe someone could help? I only can use HTML and javascript and I need to send throught get method.

I only can use HTML and javascript and I need to send throught get method.

If you must use a GET request, add a submit event listener to the form, and make the request using fetch . Then do whatever you need with the response. Note that the parameters will still be visible in the DevTools console.

// todo: add submit event listener
const input1Value = "John"; // here you need to get the values from the form inputs
const url = new URL('https://example.com');
const params = { name: input1Value };
url.search = new URLSearchParams(params).toString();
await fetch(url);

In first place, you can't, the GET method use the URL to send informations, so if you send informations, those will be in the URL.

BTW, you can use JS to delete them when the page is loaded:

<script>
(function(){
    window.history.pushState({}, document.title, location.pathname);
})()
</script>

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