views:

250

answers:

2

Hi,

I am trying to submit an HTTP request via AJAX from the client to the Google Maps Geocoding service. I keep getting a status of 0.

I know the request is valid because when I enter the URL right into the browser address bar I get a valid result. Here is the code (assume 'url_string' has a valid url to the geocoding service - I have tested this already as mentioned above):

var request = GXmlHttp.create();
request.open("GET", url_string, true);
request.onreadystatechange = function() {
    if (request.readyState == 4) {
        alert("STATUS IS "+ request.status);  
    }
}
request.send(null);

My app is running on Google appengine and I get the error when I try it locally but also when I deploy and try it.

Any help would be appreciated.

A: 

0 is the status code you get for a completely failed connection, where there is no HTTP response to return a status code from. This can be eg. various socket errors (though IE will give you a WinSock error code like 12029 in this case).

when I enter the URL right into the browser address bar I get a valid result.

I suspect the URL isn't on your server. GXmlHttp, being a tiny wrapper around XMLHttpRequest, cannot do cross-domain requests.

Use the specific class Google give you for doing geocoding rather than trying to do it with a plain XMLHttpRequest.

bobince
A: 

You can't submit your own XmlHttpRequest to Google as this violates the Same Origin Policy, and is thus being rejected by the browser. As bobince said, use Google's provided classes for doing it instead. They get around this via clever DOM hacks which you shouldn't need to reimplement.

Yuliy
Thanks very much, didn't realize the cross domain restriction.
Shazoo