Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Why Javascript fetch method putting unnecessary / in the URL

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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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); 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda