PDA

View Full Version : google gecoding service and cross domain requests



dolittle
22 Mar 2009, 10:50 AM
Hi,

I'm using google geocoding service as described here (http://code.google.com/apis/maps/documentation/services.html#Geocoding_Object):

In the example the url for the request is:

http://maps.google.com/maps/geo?output=json&...&callback=_xdc_._1fsm2u0k2
and the response:

_xdc_._1fsm2u0k2 && _xdc_._1fsm2u0k2({
"name": "1600 Amphitheatre Pky, Mountain View, CA",
"Status": {
...
...
...
}
)

I understand how cross domain requests and ScriptTagProxy works but I don't understand why google respond with:

_xdc_._1fsm2u0k2 && _xdc_._1fsm2u0k2({...
and not with:

_xdc_._1fsm2u0k2({...

Any ideas?

Thanks

Animal
22 Mar 2009, 11:26 AM
It's a truth test.

The statement will not execute unless _xdc_._1fsm2u0k2 exists

Type the following into the Firebug console:



function f(){alert(1);}


then



undefined && f()


You see that the function is not run.

dolittle
22 Mar 2009, 12:21 PM
That's interesting.

Couldn't this improve the following code in scriptTagProxy:

// private
destroyTrans : function(trans, isLoaded){
this.head.removeChild(document.getElementById(trans.scriptId));
clearTimeout(trans.timeoutId);
if(isLoaded){
window[trans.cb] = undefined;
try{
delete window[trans.cb];
}catch(e){}
}else{
// if hasn't been loaded, wait for load to remove it to prevent script error
window[trans.cb] = function(){
window[trans.cb] = undefined;
try{
delete window[trans.cb];
}catch(e){}
};
}
},
In case of a timeout failure the check if the function exist is not necessary.

Could this be a feature request?

Thanks