Google Maps API为什么会返回405错误?

问题描述:

我有我的网页上下面的jQuery的片段:Google Maps API为什么会返回405错误?

$(".lookup").click(function() { 
      var addr =  document.aspnetForm.ctl00_ContentPlaceHolder1_txtEditLocationAddr1.value + ",+" + document.aspnetForm.ctl00_ContentPlaceHolder1_txtEditLocationCity.value + ",+" + document.aspnetForm.ctl00_ContentPlaceHolder1_txtEditLocationState.value; 
      $.ajax({ 
       url: "http://maps.googleapis.com/maps/api/geocode/json?address="+escape(addr)+"&sensor=false", 
       success: function (data) { 
        var mydata = JSON.parse(data); 
        document.aspnetForm.ctl00_ContentPlaceHolder1_txtEditLocationLat.value = mydata.results[0].geometry.location.lat; 
        document.aspnetForm.ctl00_ContentPlaceHolder1_txtEditLocationLong.value = mydata.results[0].geometry.location.lng; 
       } 
      }); 
     }); 

可以看出,这需要地址,市州和邮编的当前形式值,并将其传递给谷歌API,然后解析JSON响应并在同一表单中填充经纬度字段。这段代码在我的本地机器上正常工作。但是当我把它放在我的生产服务器上时,我发现返回了一个405错误。 Google Googling 405错误后,我想可能是我的服务器正在强制POST,Google需要一个GET,但后来我用Firebug检查了这些头文件,并且它们确实以GET方式发送。

什么会导致Google返回405?解码的网址我上面用的就是:

http://maps.googleapis.com/maps/api/geocode/json?address=1630%20E.%20Lamar%20Blvd%2C+Arlington%2C+TX&sensor=false

这在地址栏正常工作为好。

感谢您的任何建议。

+0

重复? http://stackoverflow.com/questions/1783288/jquery-on-google-json-fails-with-error-405 – Kath 2012-02-08 21:10:22

无法通过AJAX访问Geocoding API。请使用Google Maps API V3中的Geocoder

这提供了对Google地理编码器的异步访问。

+0

好的。我可以轻松地尝试。为什么它会在测试模式下在本地机器上运行?它仍然是阿贾克斯?奇怪... – 2012-02-09 00:29:50

+0

这看起来很奇怪,你是对的:-) – 2012-02-09 03:57:39