Here is the script itself

$(document).ready(function(){ /* на все формы */ $('#ajax_form').submit(function(e){ //отменяем стандартное действие при отправке формы e.preventDefault(); //берем из формы метод передачи данных var m_method=$(this).attr('method'); //получаем адрес скрипта на сервере, куда нужно отправить форму var m_action=$(this).attr('action'); //то есть в стандартном формате передачи данных формы var m_data=$(this).serialize(); $.ajax({ type: m_method, url: m_action, data: m_data, success: function(result){ $('#content .row-fluid').html(result); } }); }); }); 

After submitting the form, it returns with new data and when pressed again, the AJAX no longer works. The form itself is the same, only new data is being substituted, so I’ve run out of ideas why this could be.

  • The form is randomly not inside $('#content .row-fluid') ? - Zhukov Roman
  • In it, instead of the old form, the exact same form appears, but with new data, at the same place - Tchort
  • Well, correctly, the new form already has no js-handler. Need to write differently, through .on() - Zhukov Roman
  • To be honest, I didn’t understand how to use .on () :) What exactly is wrong for this case?) - Tchort

1 answer 1

It is necessary to catch events through .on () :

 $(document).ready(function(){ $('#content').on('submit', '#ajax_form', function(e){ //отменяем стандартное действие при отправке формы e.preventDefault(); //берем из формы метод передачи данных var m_method=$(this).attr('method'); //получаем адрес скрипта на сервере, куда нужно отправить форму var m_action=$(this).attr('action'); //то есть в стандартном формате передачи данных формы var m_data=$(this).serialize(); $.ajax({ type: m_method, url: m_action, data: m_data, success: function(result){ $('#content .row-fluid').html(result); } }); }); }); 
  • And here is another similar situation, how can you manage this? $ ('# drop a'). click (function () {// Simulate a click on input $ (this). parent (). find ('input'). click (); $ .get ('/ algo / get /get_photo_user.php ', {}, function (data) {$ ('. photo_user_list '). html (data);});}); - Tchort