当我们通过指定绝对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