0

I have an "if statement" like so:

if (webservice returns true) {

                    alert("booyah");
               }

alert("hooray");

Trouble is that the webservice is very slow. And "hooray" gets triggered before "booyah" even when the webservice returns true.

How can I pause all further processing until this "if statement" is properly evaluated?

I'm thinking that some kind of callback function might be needed here. How will I structure it?

Additionally, is there some way to have a wait animation on the webpage while this "if statement" is being waited on?

thanks_in_advance
  • 2,603
  • 6
  • 28
  • 44
  • 1
    Generally yes a callback is the thing to do, but it depends how you are calling `webservice`. Are you doing a standard ajax call? Are you using jquery? It would be best to post the code to call the webservice – Rhumborl Oct 21 '14 at 09:20
  • @Rhumborl Not using jQuery. The service is navigator.geolocation , which allows a webbrowser to identify a user's location. The specific if condition is: if(navigator.geolocation) { } – thanks_in_advance Oct 21 '14 at 09:21
  • 1
    Check [this question](http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition-sometimes-works-sometimes-doesnt) and its answers. In general, it's better to be more specific when describing your problem. ) – raina77ow Oct 21 '14 at 09:26
  • @raina77ow You offered a useful link. However, that problem is about reducing the (otherwise infinite) timeout of the navigator service, whereas I want to stop all further processing until I get a yes or no reply from the service. – thanks_in_advance Oct 21 '14 at 09:36
  • @user1883050: What the example in the question shows, is *also* a callback. In other words, a function which only gets called *after* the webservice call returns. That's what you are looking for, correct? – Piskvor left the building Oct 21 '14 at 10:08

0 Answers0