0

Data is received from ajax request. BeforeSend an animated gif preloader is shown. On ajax success preloader is turned off and response is appended to a div (jQuery append).

The problem is following: when html starts building animation freezes on one frame. Preloader doesn't turn off even if code is placed before appening response data. It just freezes and looks like waits for it to finish.

Is there a workaround this issue?

P.S.: added some code to make it clearer for those that haven't understood from text:

$.ajax({
    type: 'POST',
    data: '',
    url: 'ajax_script.php',
    beforeSend : function() {
        $('.add_element_preloader').css('visibility', 'visible');  
    },
    success: function(response){                    
        $('.add_element_preloader').css('visibility', 'hidden');
        $('.container').append(response);
    }
});
Menas Eru
  • 118
  • 9
  • What about posting relevant code in question??? – A. Wolff Dec 26 '14 at 15:34
  • I have no idea if this is relevant to jQuery at all – Yorick de Wid Dec 26 '14 at 15:34
  • You don't need a code here. It just basic stuff. – Menas Eru Dec 26 '14 at 15:35
  • @YorickdeWid I had the same idea. That this is some browser issue because it's building new html-code it stops playing animation. But I hoped that there is a way to just turn it off. – Menas Eru Dec 26 '14 at 15:43
  • What does the browser console say? – Yorick de Wid Dec 26 '14 at 15:46
  • `append()` is sync as all updating DOM methods, see: http://stackoverflow.com/questions/191413/why-does-my-spinner-gif-stop-while-jquery-ajax-call-is-running So if your response is too big, this is expected behaviour – A. Wolff Dec 26 '14 at 15:51
  • @YorickdeWid Nothing at all. And I just noticed that if I leave preloader on all the time it freezes just at time of getting response and building new structure with it. – Menas Eru Dec 26 '14 at 15:52
  • @A.Wolff :)))) Your link says that problem is in browser because its UI is single threaded. But, yep, looks like this is the problem. With a lot of new structure building looks like it stops everything. I just don't get one thing. I try to turn off preloader before it starts appending new code - but it doesn't turn off. – Menas Eru Dec 26 '14 at 15:58
  • @user3725355 I guess because no redraw is called on UI, try to force UI redraw to check it, e.g, try: `$('.add_element_preloader').css('visibility', 'hidden');document.body.offsetHeight;$('.container').append(response);` – A. Wolff Dec 26 '14 at 16:02
  • @A.Wolff same problem. Animation freezes on one frame and disappears only when appending finished. – Menas Eru Dec 29 '14 at 08:27

0 Answers0