我有我的網頁上下面的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://stackoverflow.com/questions/1783288/jquery-on-google-json-fails-with-error-405 – Kath 2012-02-08 21:10:22