下面是我们代码库中现有的jQuery代码。在jquery中获取http状态代码
$("#download_").click(function() {
$("#error").html('');
$.ajax({
type : "GET",
cache : false,
async : false,
url : "/download",
success : function(data) {
var json_obj = $.parseJSON(data);
if(json_obj !== undefined && json_obj != null){
if(json_obj.download=="success"){
location=json_obj.url;
}
}
},
error : function(data) {
// TODO
$("#error").html(failed);
}
});
});
这里,在错误(标记为TODO)的情况下,我想检查HTTP状态是404,那么我就需要用户重定向到不同的URL。
任何人都可以告诉我如何在这个错误中获得http状态:function(data)method?
谢谢!
可能重复[jQuery:如何从$ .ajax.error方法获取HTTP状态代码?](http://stackoverflow.com/questions/6700822/jquery-how-to-get -the-HTTP-状态码由内最Ajax的误差法) – Andrew 2012-03-07 20:22:58