以下は、コードベースの既存の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としてマークされた)エラーの場合、私はその後、私は別のURLにユーザーをリダイレクトする必要があり、HTTPステータスが404であるかどうかを確認したいです。
このエラーでhttpステータスを取得するにはどのようにすればよいですか?function(data)method?
ありがとうございます!
の可能重複[jQueryの:?$ .ajax.errorメソッド内からHTTPステータスコードを取得する方法](http://stackoverflow.com/questions/6700822/jquery-how-to-get -http-status-code-from-the-ajax-error-method) – Andrew