資料載入中

胡言亂語

ajax錯誤訊息提示


ajax錯誤訊息提示
ajax目前已經是我寫系統使用非常普遍的方式~

雖說常寫,但偶爾還是會有鬼打牆的時候發生.......

這邊記錄一下要如何知道傳送錯誤的類型。
$.ajax({
type: 'GET',
url: headerUrl,
dataType: 'html',
success: function(data) {
$('#header').append(data);
},error: function(jqXHR, exception){
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}

alert(msg)

總之~學不完的知識。
 

https://innstory.com/story-ajax錯誤訊息提示-1766

上一篇
 分享缺電救星出現了?日本開發颱風發電機一場颱風就蘊藏50年電力不用實在太浪費!風傳媒

下一篇
使用Google提供的檢查網頁工具檢查是否為惡意網站 
  • 1,308
  • 0
  • 0

發表留言

作者簡介

離不開電腦的宅男


推薦閱讀

作者其他相關類別故事

如何將mysql table auto_increment重設

如何將mysql table…

Mark Chang 7 年又 100 天 2.2K

資料表裡的資料加加減減,一不小心突然驚覺當初的欄位長度設定的不夠⊙⊙ 當然,你可以選擇再把欄位長度...

設置屬性 PHP PDO setAttribute

設置屬性 PHP PDO s…

Mark Chang 5 年又 134 天 1.4K

以上紀錄  

CSSobject-fit 屬性用於指定應如何調整 img或video的大小以適合其容器

CSSobject-fit …

Mark Chang 4 年又 107 天 1.3K

在UI排版時常會遇到一個問題,後台上傳的圖片比例無法符合前台顯示的DIV容器。 以前我比較常用的方...