26 lines
1.2 KiB
JavaScript
26 lines
1.2 KiB
JavaScript
|
document.addEventListener('DOMContentLoaded', async () => {
|
||
|
const urlParams = new URLSearchParams(window.location.search);
|
||
|
const bookId = urlParams.get('id');
|
||
|
|
||
|
try {
|
||
|
const response = await fetch(`/api/ksiazki/${bookId}`);
|
||
|
if (!response.ok) throw new Error('Książka nie znaleziona');
|
||
|
|
||
|
const book = await response.json();
|
||
|
|
||
|
document.getElementById('book-title').textContent = book.tytul;
|
||
|
document.getElementById('book-author').textContent = `Autor: ${book.autor}`;
|
||
|
document.getElementById('book-price').textContent = `Cena: ${book.cena} PLN`;
|
||
|
document.getElementById('book-description').textContent = book.opis || 'Brak opisu';
|
||
|
document.getElementById('book-cover').src = book.obraz_url || 'https://via.placeholder.com/400x600';
|
||
|
} catch (error) {
|
||
|
console.error('Błąd:', error);
|
||
|
document.getElementById('book-details').innerHTML = `
|
||
|
<div class="col-12 text-center">
|
||
|
<h2 class="text-danger">Książka nie znaleziona</h2>
|
||
|
<a href="/" class="btn btn-gothic mt-3">Powrót do strony głównej</a>
|
||
|
</div>
|
||
|
`;
|
||
|
}
|
||
|
});
|