28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const voteButtons = document.querySelectorAll('.vote-buttons a');
|
|
|
|
voteButtons.forEach(button => {
|
|
button.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const url = this.href;
|
|
const likeCountSpan = this.querySelector('span');
|
|
const dislikeButton = this.parentElement.querySelector('.dislike-button');
|
|
const dislikeCountSpan = dislikeButton.querySelector('span');
|
|
|
|
fetch(url)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
likeCountSpan.textContent = data.likes;
|
|
dislikeCountSpan.textContent = data.dislikes;
|
|
} else {
|
|
// Handle errors if needed
|
|
console.error(data.error);
|
|
}
|
|
})
|
|
.catch(error => console.error('Error:', error));
|
|
});
|
|
});
|
|
});
|