【发布时间】:2012-02-09 05:21:19
【问题描述】:
我的页面上有以下 jquery sn-p:
$(".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;
}
});
});
可以看出,这会将地址、城市状态和 zip 的当前表单值传递给 Google API,然后解析 JSON 响应并在同一表单上填充纬度和经度字段。这段代码在我的本地机器上运行良好。但是当我把它放在我的生产服务器上时,我看到一个 405 错误返回。在谷歌搜索 405 错误之后,我想也许我的服务器正在强制执行 POST,而 Google 需要 GET,但后来我使用 Firebug 检查了标头,它们肯定是作为 GET 发送的。
什么会导致 Google 返回 405?我上面使用的解码后的网址是:
这在地址栏中也可以正常工作。
感谢您的任何建议。
【问题讨论】: