I am facing a problem with Axios GET query string parameter when string includes "+" or "&" signs. I have tried using encodeURIComponent and I get
http://localhost:8001/api/data?page=1&paginate=20&term=S%2BM%20Company
When trying to query for S+M Company which is located as a value in the database table. Trying to query just a string without encoding it breaks after
http://localhost:8001/api/data?page=1&paginate=20&term=S+M.
The string is added to url from plain text field and the var is
url = url + &term=${this.search}
Any suggestions would be highly appreciated. Thanks!
There is a built in helper for that:
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams
Use it like:
const data = {
queryOne: 'value1',
queryTwo: 'value2'
};
const myParams = new URLSearchParams(data);
myParams.toString()