當我們通過指定絕對url調用外部web服務時,是否有可能捕獲HTTP錯誤(如404,500,504等)? (比如設置$.ajax
呼叫url:
屬性有一個URL值http://api.geonames.org/findNearbyPostalCodes
。jQuery ajax - 絕對URL和錯誤處理
現在我無法雖然Firebug是趕上他們,並顯示在控制檯它收到任何錯誤。
誰能幫?
這裏是我的代碼。
$.ajax({
type: 'GET',
url: "http://api.geonames.org/findNearbyPostalCodes",
data: '{"lat":47,"lng":"9","username":"demo"}',
dataType: 'json',
cache:false,
async:false,
statusCode:{
404: function(){
alert('Page not found');
},
500: function(){
alert('Page not found');
},
504: function(){
alert('Unknown host');
}
},
success: function(data){
alert(data);
}
error: function (xhr, exception, thrownError)
{
alert(xhr.status);
}
});
是否正在執行錯誤塊的警報? – 2012-03-20 16:24:16
成功回調後,您錯過了逗號 – bevacqua 2012-03-20 16:25:47
錯誤回調或錯誤複製/粘貼之前缺少逗號? – soju 2012-03-20 16:27:44