处理403错误 - 谷歌地图w / jQuery.getScript

时间:2012-08-22 10:18:01

标签: jquery google-maps http-status-code-403

我正在使用jQuery.getScript使用API​​密钥动态加载google-maps。

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

1 个答案:

答案 0 :(得分:0)

查看documentation

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