ajax錯誤時,可利用error來handle錯誤處理
從xhr中,可取得回傳的error message
從xhr.status得知錯誤代碼是什麼,也就是http status codes
再針對不同的status做處理囉
xhr是XMLHttpRequest物件,有以下屬性及方法
從xhr中,可取得回傳的error message
從xhr.status得知錯誤代碼是什麼,也就是http status codes
再針對不同的status做處理囉
jQuery.ajax({
url: "http://xxx",
...
error:function (xhr, ajaxOptions, thrownError){
$("body").append(xhr.status);
$("body").append(xhr.responseText );
alert(thrownError);
}
});
xhr是XMLHttpRequest物件,有以下屬性及方法
- status
Returns the HTTP status code. - statusText
Returns the HTTP status text. - getResponseHeader() method
- getAllResponseHeaders() method
- Response Entity Body
- responseText attribute
Returns 就回傳取到的內容囉 - responseXML attribute
沒有留言:
張貼留言