AJAX button action in foreach

This is happening because you have click event firing on ID

jQuery('#przyciskUlubione').click(function() {

The ID is always unique, there should never be more than one same ID in the HTML.

You can achieve this using class. Assign the same class to all the buttons.

Change your selector to class:

jQuery('.przyciskUlubione').click(function() {

add value attribute or data attribute to your buttons.

Now, When you will click on any button the click event will be triggered. You now need to fetch value using this.

Next step: replace your line

$("#przyciskUlubione").val()

With this:

$(this).val()

This should work properly 🙂