的的getJSON()調用我正在使用新的 Google Time Zone API錯誤在新的谷歌時區API
我用它來知道在地圖的緯度/長點的準確時間。
首先,我讀到Google在6天前(2012年10月10日)發佈了這個api,所以我沒有找到關於這個API調用的文檔。
我有以下問題:
谷歌強迫你使用https,而我得到的跨域錯誤:
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/timezone/json?location=35.209722,-118.300781×tamp=1350372338&sensor=false Origin http://my_web is not allowed by Access-Control-Allow-Origin.
這是我的代碼來獲得JSON:
url = "https://maps.googleapis.com/maps/api/timezone/json?location=35.209722,-118.300781×tamp=1350372338&sensor=false";
$.ajax({
url: url,
//data: {},
type: "GET",
crossDomain: true,
dataType: 'json',
//processData: false,
success: function (data) {
console.log('Succes!! Read some data...');
},
error: function (xhr, err) {
console.log("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
console.log("responseText: " + xhr.responseText);
}
});
在許多帖子中建議使用JSONP而不是JSON,但問題在於Google僅以JSON和XML提供響應。
有沒有人知道我怎麼可以做一個GET請求的https沒有跨域問題?
謝謝你!
所以我將無法從Javascript查詢? 隨着Geonames服務,我沒有任何問題,因爲它是http,而不是https。 所以看來問題是該網址是https類型?因爲使用http URL,如果有效的話。謝謝! – Adagio
最後我打電話從一個PHP。從Javascript是不可能的。 – Adagio