Why the thumb is overlaid with each AJAX'ohms?

By clicking on the button sent POST data, the submit button disappears and appears in another form. In this form there are 2 custom buttons here's part of code:
$.ajax({
 url: "addPhotos.php",
 type: "POST",
 data: post,
 success: function (response) {
alert(1);
 let btns = {};
 $.each($('.block-photos__list-btn'), function() {
 $(this).on("click", function() {
alert(2);
$(this).toggleClass("rotate180");
})
 if (/ANNOUNCEMENT/.test($(this).parent().html())) {
 return btns.mainBtn = $(this);
 } else {
 return btns.colorBtn = $(this);
}
 })

Here you can see that the response from the server I put alert(1). And when you click on the button $(this) - alert(2), and there switch the class.
The first time you submit everything works fine, but if you go back (there is a button that hides the form and shows the first button), and click on the button, sending AJAX again, by clicking on the alert(2) POPs up 2 times! Send ajax again - 3 times! In this case alert(1) is always 1, ie just goes to a new ajax and comes on every time the answer 1 time. What with buttons?
Tried an ad a little change:
let btns = {
 "mainBtn": undefined,
 "colorBtn": undefined
 };

does not help.
March 23rd 20 at 19:12
2 answers
March 23rd 20 at 19:14
Solution
Why the thumb is overlaid with each AJAX'ohms?

Because every AJAX'om you install (add) a new event handler
$(this).on("click", function() {
try to replace
$(this).off("click").on("click", function() {

* First remove all previously created handlers .off(), then set .on()
Gun!) - Rossie_Bashirian commented on March 23rd 20 at 19:17
I'm sorry, 96% of the solutions, in the experts there, and who were invited - silent, the third time the question is asked, can I see it?) - Rossie_Bashirian commented on March 23rd 20 at 19:20
@Rossie_Bashirian, Hello, day, a busy.
In answer to your question already gave a perfectly acceptable option. Especially read the link "read More" to understand how it works. Success! - maya commented on March 23rd 20 at 19:23
March 23rd 20 at 19:16
The whole point is $(this).on("click", function() {

alert(1) is called each time when a successful response from the server, exactly like $(this).on("click", function() {. Here it is important to understand that $(this).on("click" no frays the old handler, instead they accumulate.

The solution to your problem is to put the code
$(this).on("click", function() {
alert(2);
$(this).toggleClass("rotate180");
})

of succses handler.
did not help
I took to a function and call this function..
Without this in any way, the buttons process the response the response that argument pass - Rossie_Bashirian commented on March 23rd 20 at 19:19
You can "grind" somehow? I have these clicks several times called for different buttons at different points, and all response from the independent.. - Rossie_Bashirian commented on March 23rd 20 at 19:22
ie itself is the onclick event in other places working with the server response...
If you make - you need to send a response, and the answer is always different and every time when transmitting response calls sobita onclick, otherwise you will not make - Rossie_Bashirian commented on March 23rd 20 at 19:25

Find more questions by tags jQuery