How do you make javascript code execute *in order*

后端 未结 9 1195
别那么骄傲
别那么骄傲 2020-11-30 05:49

Okay, so I appreciate that Javascript is not C# or PHP, but I keep coming back to an issue in Javascript - not with JS itself but my use of it.

I have a function:

9条回答
  •  长情又很酷
    2020-11-30 06:43

    Install Firebug, then add a line like this to each of showLoader, updateStatus and hideLoader:

    Console.log("event logged");
    

    You'll see listed in the console window the calls to your function, and they will be in order. The question, is what does your "updateStatus" method do?

    Presumably it starts a background task, then returns, so you will reach the call to hideLoader before any of the background tasks finish. Your Ajax library probably has an "OnComplete" or "OnFinished" callback - call the following updateStatus from there.

提交回复
热议问题