Please help me figure it out.

Here there is page A, from it the Ajax is sent to page B, from there it returns to page A through .html(data) . On page B, a script is generated that looks like this $('.class').click(так далее) .

The problem is this: when sending 2 times Ajax, 2 scripts are returned and it turns out that when you press the button, the script is processed 2 times, if you send the Ajax 3 times, 3 times it will be how to make sure that the previous script was erased and only one remained, at least once ajax

  • Well, delete before adding. - KoVadim
  • 2
    Why do you send the script at all? - etki

2 answers 2

Clear the event.

 $(".class").unbind( "click" ); 

or do not add if such an event already exists

  • add event also through bind $ (". class"). bind ("click", function () {code-request ajax}); - Valentin Zhukov

On page A, write once a view script:

 $(document).on('click','.class', function() { // some code }); 

On page B to form and transmit only html, without scripts. The handler described above will serve clicks on all elements with class class. And do not need to erase and reassign.