a javascipt qustion
-
Hi everybody,I'm a new comer to javascript.I have a question.English is not my mother language.I'll try my best to explain clearly what I mean. Look at the following code:
var CallComplete; function MyFunction() { CallComplete = false; //Make asynchronous call of a server method SeverMethod(CallBack); //wating for CallComplete //but it takes such a long time to waiting the call complete while (!CallComplete) { } return something; } function CallBack(response) { ... CallComplete = true; }
The ServerMethod is quite simple,and it will return immediately if I remove the while loop from the above code.But MyFuntion must wait for the severmethod's data to return values. Is there any better way waiting for the asynchronous call complete? Any idea will be appropriate. -
Hi everybody,I'm a new comer to javascript.I have a question.English is not my mother language.I'll try my best to explain clearly what I mean. Look at the following code:
var CallComplete; function MyFunction() { CallComplete = false; //Make asynchronous call of a server method SeverMethod(CallBack); //wating for CallComplete //but it takes such a long time to waiting the call complete while (!CallComplete) { } return something; } function CallBack(response) { ... CallComplete = true; }
The ServerMethod is quite simple,and it will return immediately if I remove the while loop from the above code.But MyFuntion must wait for the severmethod's data to return values. Is there any better way waiting for the asynchronous call complete? Any idea will be appropriate.The reason for having a callback is that you don't need to wait for the call to complete. When it completes the callback method is executed. Whatever you need to do after the call completes, you can put in the callback method. --- b { font-weight: normal; }