There is a cycle (see below // data retrieval cycle). Insertion of class on event is inserted into the loop. This class $ processing ('. Picttime') does not work anywhere else. Asynchronous functions cling one after another in order not to lose the data loaded from the databases (data3, data4). First, the loop processes the drawing of the dynamic table, BUT then the processing of the class repeats an equal number of iterations. It is necessary that class processing be performed once after the loop has been executed. I had a successful execution of the cycle, and then the function. But I wanted the function to execute once. Outside the loop, the function does not work, inside the loop in the function, the loop termination did - the loop execution is interrupted. Asynchrony is something. In order to transfer the results from one function to another, all my asynchronous functions are folded one to another like a nested doll. All the functions I have is the completion of data from the databases (.load). Somehow like this. The second question: can you tell me how, after completing one asynchronous function, get the data from it and enter it into another function. To get not a matryoshka and a sequence. I understand that the matryoshka is a good time saving with asynchronous processing, but with a tenfold investment you need to interrupt the growing com.

$("#...").load('....php',{},function(data3){ // получаем данные с базы №1 for(i=0; i < j; i++) //цикл перебора данных { $("#...").load('....php',{}, function(data4){ // получаем данные с базы №2 ... for(var z=1; z<(h4-h1+n); z++) //цикл обработки и создания таблицы { timeSotr = timeSotr + "<td><table id='tabl_lg_"+lgUs+"_row_"+np+"' name=='tabl_lg_"+lgUs+"_row_"+np+"' class='minifont'><tr>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_10' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_10' value='.' class='but picktime'></td>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_20' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_20' value='.' class='but picktime'></td>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_30' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_30' value='.' class='but picktime'></td>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_40' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_40' value='.' class='but picktime'></td>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_50' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_50' value='.' class='but picktime'></td>"+ "<td><input type='button' id='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_60' name='_lg_"+lgUs+"_row_"+np+"_h_"+(h1+z-1)+"_m_60' value='.' class='but picktime'></td></tr></table></td>"; } timeSotr = timeSotr + "</tr></table>"; $('#t'+i+'n3').html(timeSotr); $('.picktime').click(function(){ //класс обработки, должен выполняться один раз }); }); } }); 
  • 2
    The case when it's time to study promises (Promises) . - Pavel Mayorov
  • $('body').one('click', '.picktime', function(){}); out of cycle - br3t
  • Thanks, I started studying, I did not use it before. - VitVlad
  • br3t failed. On the first iteration of the loop, the handler runs on the second one. The handler moved immediately after the loop. - VitVlad
  • br3t, figured out. Yes, it really works only once. Those. If you use event handling again, it does not work. It was meant that during processing the handler function was executed as many times as iterations in the loop. Now it is executed once. I would like the handler to be executed again when pressed again. - VitVlad

0