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!
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.