Show Page Loading Spinner on Ajax Call in jQuery Mobile

后端 未结 8 1919
说谎
说谎 2020-11-29 23:42

I\'m using $.ajax() to populate a list in my mobile web app. What I\'d like to do is have the jQuery mobile loading spinner appears while this call is being performed and di

8条回答
  •  孤独总比滥情好
    2020-11-30 00:23

    The problem here is that the call to $.ajax() happens within the control flow of the event handler (the caller).

    A very simple way to decouple the ajax request from this control flow is to let setTimeout() invoke this function for you, like so:

    setTimeout(function(){$.ajax( ... )}, 1);
    

    You can then use the 'beforeSend' and 'complete' events of $.ajax() as stated before and be sure, that your spinner is showing up.

提交回复
热议问题