Skip to content

Commit

Permalink
Making the event listener stop reproducing
Browse files Browse the repository at this point in the history
  • Loading branch information
starstryder committed Aug 12, 2024
1 parent 2e18ba4 commit 669aa69
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions csb/csb-apps/Mosaic/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,34 @@
// Function to Load Image
function loadImage() {
fetch('csb-apps/Mosaic/writeMosaicData.php') // Make the request to your PHP file
// put the response from the php file into the div testDiv
.then(response => response.json())
.then(data => {
document.getElementById('currentImage').src = data.imageUrl;
document.getElementById('currentImage').setAttribute('data-image-id', data.imageId);
document.getElementById('test').innerHTML = data.imageId;
});

// Add event listener to listen for clicks on a button
const buttons = document.querySelectorAll('.btn-primary');
buttons.forEach(button => {
button.addEventListener('click', function() {
const buttonValue = button.value;
const imageId = document.getElementById('currentImage').getAttribute('data-image-id');
const userId = <?php echo $_SESSION['user_id']; ?>;
// put the response from the php file into the div testDiv
.then(response => response.json())
.then(data => {
document.getElementById('currentImage').src = data.imageUrl;
document.getElementById('currentImage').setAttribute('data-image-id', data.imageId);
document.getElementById('test').innerHTML = data.imageId;
});
}
// Add event listener to listen for clicks on a button
const buttons = document.querySelectorAll('.btn-primary');
buttons.forEach(button => {
button.addEventListener('click', function() {
const buttonValue = button.value;
const imageId = document.getElementById('currentImage').getAttribute('data-image-id');
const userId = <?php echo $_SESSION['user_id']; ?>;

// send the data to the php file as variables
fetch('csb-apps/Mosaic/writeMosaicData.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: 'buttonvalue=' + buttonValue + '&imageId=' + imageId + '&userId=' + userId
});
// send the data to the php file as variables
fetch('csb-apps/Mosaic/writeMosaicData.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'buttonvalue=' + buttonValue + '&imageId=' + imageId + '&userId=' + userId
});

// load the next image
loadImage();
// load the next image
loadImage();

});
});
}
});
</script>

0 comments on commit 669aa69

Please sign in to comment.