2012-08-22 46 views
0

我正在使用jQuery.getScript來動態加載google-maps與API-key。句柄403錯誤 - Google Maps w/jQuery.getScript

jQuery.getScript("http://maps.googleapis.com/maps/api/js?sensor=false&key=APPKEY&callback=initMap", function(data, textStatus, jqxhr) { 
    console.log(textStatus); //success 
    console.log('Load was performed.'); 
    console.log(jqxhr.status); //200 
}); 


function initMap(){ 
var mapOptions = {   
center: new google.maps.LatLng(25.245178, 55.359438),   
zoom : 15, 
mapTypeId : google.maps.MapTypeId.ROADMAP, 
mapTypeControl : false 
};   
var map = new google.maps.Map(document.getElementById("map_canvas"),    mapOptions);  

} 

地圖載入現在和日誌「200」作爲jqxhr.status

隨着getScript API,我將能夠處理403錯誤,在情況下,如果它被拋出OVER_QUERY_LIMIT正常工作?

我會得到jqxhr.status=403還是應該使用fail(callback)方法?

我使用jQuery V1.7.2

+0

什麼問題是你想解決?我不認爲_API_的加載會返回OVER_QUERY_LIMIT。 – geocodezip

+0

@geocodezip所以,當這個OVER_QUERY_LIMIT將被拋出?我已經添加了我的initMap callback.Pls建議。 –

+0

當您調用Web服務或對其有配額或速率限制的JavaScript服務(即Geocoder或directionsService)時,會發生OVER_QUERY_LIMIT錯誤,並且您超過該限制。 – geocodezip

回答

0

看看在documentation

$.getScript("ajax/test.js") 
.done(function(script, textStatus) { 
    console.log(textStatus); 
}) 
.fail(function(jqxhr, settings, exception) { 
    $("div.log").text("Triggered ajaxError handler."); 
}); 
+0

我瀏覽了文檔,但是能否處理Google-Map-API的403錯誤?任何其他的鏈接,你必須處理getScript的403錯誤? –

+0

任何4xx狀態碼顯然都是錯誤的,所以將在fail()處理程序中處理。 – eWolf