开发者

goMap / Jquery - stopping status check from getting blank response before Google map completes Geocode check

开发者 https://www.devze.com 2023-02-08 04:31 出处:网络
I\'ve been adding some custom functions to the GoMap Google Map library, but have run across a problem where I want to check if an address is valid b开发者_高级运维ut my external function keeps runnin

I've been adding some custom functions to the GoMap Google Map library, but have run across a problem where I want to check if an address is valid b开发者_高级运维ut my external function keeps running without waiting for the actual response.

Inside the GoMap code I have created this function:

checkAddressExists: function(options){

        address = options.address;
        geocoder.geocode( { 'address': address}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {
              return true;  
              } else {
                return false;
              }
            });

This function works as it should and returns true or false.

However, in my external Javascript files, if I do something like:

var foo = $.goMap.checkAddressExists({address: address});

Foo remains undefined i.e it isn't waiting for the response before deciding whether it's true or false.

I have tried this but get nothing returned:

$.goMap.checkAddressExists({address: address}, function(response){
    alert(response);
});

Is there a way of making it pause to wait for the correct response from the library - or is it just that the GoMap library is not set up to provide a response?

I understand this may be a GoMap specific question, but just in case I'm missing a basic Jquery concept it's worth asking.


No.

AJAX is asynchronous and will not wait for the server to reply.
It is not possible to wait for the server to reply without freezing the browser.

jQuery 1.5's Deferred Objects can make this easier to work with.

0

精彩评论

暂无评论...
验证码 换一张
取 消