I am sending a GET request with parameters on the URL. The problem is that, While sending a request, The URL is modified and includes an extra "/" which is not by me. I am also using Django.
Code:
let url = `ajax_vehical_types`;
groups.map(async (x, i) => {
if (i === 0) url += `?group[${i}]=${x}`;
else url += `&group[${i}]=${x}`;
});
vehical_type = await fetch(`${window.location.origin}/${url}`)
.then((res) => res.json())
.then((data) => data);
Here is the result Image showing the console with fetch request
You can make usage of the URL interface. The advantage of this is that you don't need to bother about the construction of your URL and also about the URL encoding.
Please see the following example:
const groups = ["foo", "bar"];
const url = new URL(location.href);
groups.forEach((x, i) => url.searchParams.append(`group[${i}]`, x));
vehical_type = await fetch(url.toString())
.then((res) => res.json())
.then((data) => data);