I upload data (li) to ul via ajax - a few elements that can be clicked, in consequence of which the elements change color. The data is uploaded perfectly, but the fact is that after they appear, the color change on a click does not occur. I looked in F12 - there the elements li seem to blink (it is possible to load to the end). As soon as they miss, everything works. If you put async: false, then when downloading data, everything hangs, but as soon as data appears, everything works as it should. Tell me please, is it possible at the moment of hangup to display some kind of gif (no matter where) the simulated download? And after downloading, delete it. Thank you all in advance for your help!

j("#dtpk").bind("DOMSubtreeModified", function(){ var date = j("#dtpk").val(); j("ul").addClass("loading"); j.ajax({ type: "POST", url: ajax_bind.ajaxurl, async:true, data: { action: "bind", date: date }, beforeSend: function(){ j("ul").addClass("loading"); }, success: function(html){ j("#time-list").html(html); //<ul id="time-list"> }, complete: function(){ j("ul").removeClass("loader"); } }); }); 

Reported as a duplicate by Pavel Mayorov , Grundy javascript Jul 3 '17 at 6:04 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    Use beforeSend to display the indicator and success to hide it.

     $.ajax({ type: "POST", url: "script.php", data: "param=val&param=val", beforeSend: function() { $("#loading-image").show(); }, success: function(msg) { $("#"+div_id).html(divIdHtml + msg); $("#loading-image").hide(); } }); 
    • Already tried this option, and with the addition of compete, nothing changes. Visually, the data appears within 1-2 seconds, but the functionality works out after 5-7. - dexploizer
    • @YuriGo add $("#loading-image").show(); before $.ajax({ - JVic
    • gif appears simultaneously with li elements (li over gif) - the result is the same .. - dexploizer
    • one
      Then add code samples to the question - JVic
    • Added, please see - dexploizer