Wait until a condition is true?

前端 未结 7 1936
日久生厌
日久生厌 2020-12-09 08:32

I\'m using navigator.geolocation.watchPosition in JavaScript, and I want a way to deal with the possibility that the user might submit a form relying on locatio

7条回答
  •  萌比男神i
    2020-12-09 09:28

    You could use a timeout to try to re-submit the form:

    $('#route-form').submit(function(event) {
        // User submits form, we need their location...
        if(current_location==null) {
            toastMessage('Waiting for your location...');
            setTimeout(function(){ $('#route-form').submit(); }, 500); // Try to submit form after timeout
            return false;
        } else {
            // Continue with location found...
        }
    });
    

提交回复
热议问题