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

205
Visualizações
How to make site more dynamic/save using same code?

I am currently working on a project, which has many html sites with the same structure. So the code is basically the same. The only difference these sites have, is that with each site I am accessing a different "partition" from my database. This is in the script tag:

<script>
    const api_url = 'urlhere';

async function getRating(){
    const response = await fetch(api_url);
    const data=await response.json();
    const myReviews = data;

  

    document.getElementById('Name').textContent = myReviews[0].PartitionKey;
    document.getElementById('Genre').textContent = myReviews[0].RowKey;
    document.getElementById('Seasons').textContent = myReviews[0].Seasons;
    document.getElementById('Description').textContent = myReviews[0].Description;
    document.getElementById('Rating').textContent = myReviews[0].Rating;
    document.getElementById('Review').textContent = myReviews[0].Review;

    console.log('Success');
}

The html part before contains things like images and a nav bar. But that is the same code every time. Is there a possibility that I can click on a button with the name of a show (e.g show 1) and that the show can be displayed dynamically via get parameter? ( Click on Button, Link changes depending on show -> http://www.test.com/index.html*?show=show1 , Website gets data from Database depending on Link)

Or do you have other solutions for my problem?

I hope you understand what I am trying to do, I am a beginner so I am not sure if I phrased it right or if it is even possible like that.

Happy for every answer!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Im not sure if i got your question right but im going to answer parts of it :

To get a query string value from the url in your case you want to get the 'show' parameter you could use :

const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const show_param = params.show ? params.show : "default";

And based on the 'show_param' variable you can change the source of your data or pass it as a parameter to your API end point

I'm not sure if the buttons 'show X' are in the same file if they are you can simply recall the function that gets the data and reset it to the respective elements.

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