Skip to content

Commit e8437d8

Browse files
committed
Add JavaScript error handling in upload fc2blog#140
1 parent 7bcd2ea commit e8437d8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

app/twig_templates/admin/files/ajax_index.twig

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
return false;
8181
});
8282
83-
// ファイル削除ボタン
83+
// 複数ファイル削除ボタン
8484
$('#sys-delete-button').click(function () {
8585
if (!confirm('{{ _('Are you sure you want to delete?') }}')) {
8686
return;
@@ -108,6 +108,14 @@
108108
// 削除完了後検索処理を実行
109109
isAjaxSubmit = isPageChange = true;
110110
ajaxSubmit();
111+
},
112+
error: function( response, status, xhr ) {
113+
if (status === "error") {
114+
alert("エラーが発生しました、ページをリロードしてください。\n" +
115+
"Request failed. Please reload page and retry.");
116+
isAjaxSubmit = isPageChange = true;
117+
ajaxSubmit();
118+
}
111119
}
112120
});
113121
return false;

app/twig_templates/admin/files/upload.twig

+13-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
common.formEnterNonSubmit('sys-file-form');
4343
4444
// ajaxで一覧情報をロード
45-
$('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}')
45+
$('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}', writeErrToSysAjaxFilesIndex)
4646
});
4747
4848
// ページ数初期化有無フラグ
@@ -64,7 +64,8 @@
6464
success: function (res) {
6565
$('#sys-ajax-files-index').html(res);
6666
isAjaxSubmit = true;
67-
}
67+
},
68+
error: writeErrToSysAjaxFilesIndex
6869
});
6970
return;
7071
}
@@ -85,7 +86,8 @@
8586
success: function (res) {
8687
$('#sys-ajax-files-index').html(res);
8788
isAjaxSubmit = true;
88-
}
89+
},
90+
error: writeErrToSysAjaxFilesIndex
8991
});
9092
}
9193
@@ -102,5 +104,13 @@
102104
$('input[name=order]').val(order);
103105
ajaxSubmit();
104106
}
107+
108+
function writeErrToSysAjaxFilesIndex( response, status, xhr ) {
109+
if ( status === "error" ) {
110+
$('#sys-ajax-files-index')
111+
.html("<div style='text-align: center; font-size: 2em; font-weight:bold'>エラーが発生しました、ページをリロードしてください。<br>" +
112+
"Loading error. Please reload page.</div>");
113+
}
114+
}
105115
</script>
106116
{% endblock %}

0 commit comments

Comments
 (0)