In a web application that makes use of AJAX calls, I need to submit a request but add a parameter to the end of the URL, for example:
Original URL:
Try this.
// uses the URL class function setParam(key, value) { let url = new URL(window.document.location); let params = new URLSearchParams(url.search.slice(1)); if (params.has(key)) { params.set(key, value); }else { params.append(key, value); } }