Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda