Home > Blockchain >  Why does "?a=a" get added to the back of my URL on GET?
Why does "?a=a" get added to the back of my URL on GET?

Time:10-08

I use a post GET request with action="/sact/${searchp}/" in order to submit an user search query.

var searchp = search.querySelector("input.search-input").value;
// returns the normal value

document.body.innerHTML  = `<form id="jsForm" action="/sact/${search}/" method="GET"><input type="hidden" name="a" value="a"></form>`;
document.getElementById("jsForm").submit();

This redirects here:

router.get('/sact/:where', async (req, res, next) => {
  res.render('search');
});

I can't figure out why /?a=a gets added to the back of the URL every time it gets submitted. How do I remove it?

CodePudding user response:

When you document.getElementById("jsForm").submit(); will send the form on the URL as query parameters because you are using method="GET"

The a=a is from this field <input type="hidden" name="a" value="a"> is hidden on the HTML but still will be send on the URL

if you want to "hide" you could use method="POST" won't be visible on the URL

  • Related