improve reuseability of ajax error handler

This commit is contained in:
printempw 2016-07-23 15:28:12 +08:00
parent c978ce5594
commit 4dcb5772a6
5 changed files with 42 additions and 94 deletions

View File

@ -2,7 +2,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-22 14:02:44 * @Date: 2016-07-22 14:02:44
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-07-23 15:17:22 * @Last Modified time: 2016-07-23 15:22:01
*/ */
'use strict'; 'use strict';
@ -32,9 +32,7 @@ $('#color-submit').click(function() {
else else
toastr.warning(json.msg); toastr.warning(json.msg);
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
}); });
@ -69,9 +67,7 @@ function changeUserEmail(uid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -93,9 +89,7 @@ function changeUserNickName(uid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -115,9 +109,7 @@ function changeUserPwd(uid) {
else else
toastr.warning(json.msg); toastr.warning(json.msg);
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -135,9 +127,7 @@ function changeUserScore(uid, score) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -159,9 +149,7 @@ function changePermission(uid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -181,9 +169,7 @@ function deleteUserAccount(uid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -207,9 +193,7 @@ $('body').on('change', '#preference', function() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
}); });
@ -256,9 +240,7 @@ function ajaxChangeTexture(pid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -280,8 +262,6 @@ function changeOwner(pid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }

View File

@ -1,8 +1,8 @@
/* /*
* @Author: printempw * @Author: printempw
* @Date: 2016-07-17 10:54:22 * @Date: 2016-07-17 10:54:22
* @Last Modified by: prpr * @Last Modified by: printempw
* @Last Modified time: 2016-07-21 18:02:56 * @Last Modified time: 2016-07-23 15:26:48
*/ */
'use strict'; 'use strict';
@ -72,7 +72,7 @@ $('#login-button').click(function() {
} }
}, },
error: function(json) { error: function(json) {
showModal(json.responseText, 'Fatal Error', 'danger'); showAjaxError(json);
$('#login-button').html('登录').prop('disabled', ''); $('#login-button').html('登录').prop('disabled', '');
} }
}); });
@ -135,7 +135,7 @@ $('#register-button').click(function() {
} }
}, },
error: function(json) { error: function(json) {
showModal(json.responseText, 'Fatal Error', 'danger'); showAjaxError(json);
$('#register-button').html('注册').prop('disabled', ''); $('#register-button').html('注册').prop('disabled', '');
} }
}); });
@ -178,7 +178,7 @@ $('#forgot-button').click(function() {
} }
}, },
error: function(json) { error: function(json) {
showModal(json.responseText, 'Fatal Error', 'danger'); showAjaxError(json);
$('#forgot-button').html('发送').prop('disabled', ''); $('#forgot-button').html('发送').prop('disabled', '');
} }
}); });
@ -220,7 +220,7 @@ $('#reset-button').click(function() {
} }
}, },
error: function(json) { error: function(json) {
showModal(json.responseText, 'Fatal Error', 'danger'); showAjaxError(json);
$('#reset-button').html('重置').prop('disabled', ''); $('#reset-button').html('重置').prop('disabled', '');
} }
}); });

View File

@ -2,7 +2,7 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-07-19 10:46:38 * @Date: 2016-07-19 10:46:38
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-07-23 12:10:01 * @Last Modified time: 2016-07-23 15:23:19
*/ */
'use strict'; 'use strict';
@ -59,9 +59,7 @@ function ajaxAddToCloset(tid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -81,9 +79,7 @@ function removeFromCloset(tid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -213,9 +209,7 @@ function changePrivacy(tid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -235,8 +229,6 @@ function deleteTexture(tid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }

View File

@ -1,8 +1,8 @@
/* /*
* @Author: printempw * @Author: printempw
* @Date: 2016-07-16 10:02:24 * @Date: 2016-07-16 10:02:24
* @Last Modified by: prpr * @Last Modified by: printempw
* @Last Modified time: 2016-07-21 19:53:24 * @Last Modified time: 2016-07-23 15:23:31
*/ */
'use strict'; 'use strict';
@ -59,9 +59,7 @@ $('body').on('click', '.player', function() {
MSP.changeCape(''); MSP.changeCape('');
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
}); });
@ -73,9 +71,7 @@ function getHashFromTid(tid, callback) {
success: function(json) { success: function(json) {
callback(json.hash) callback(json.hash)
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -145,9 +141,7 @@ $('body').on('click', '.item', function() {
MSP.changeSkin('../textures/' + json.hash); MSP.changeSkin('../textures/' + json.hash);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
}); });
@ -165,9 +159,7 @@ function removeFromCloset(tid) {
else else
toastr.warning(json.msg); toastr.warning(json.msg);
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -190,9 +182,7 @@ function setAsAvatar(tid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -250,9 +240,7 @@ $('body').on('change', '#preference', function() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
}); });
@ -274,9 +262,7 @@ function changePlayerMame(pid, current_player_name) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -295,9 +281,7 @@ function clearTexture(pid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -317,9 +301,7 @@ function deletePlayer(pid) {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -338,9 +320,7 @@ function addNewPlayer() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -369,9 +349,7 @@ function changeNickName() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -453,9 +431,7 @@ function changeEmail() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -482,9 +458,7 @@ function deleteAccount() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }
@ -528,8 +502,6 @@ function sign() {
toastr.warning(json.msg); toastr.warning(json.msg);
} }
}, },
error: function(json) { error: showAjaxError
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
}); });
} }

View File

@ -16,6 +16,10 @@ function showMsg(msg, type) {
$("[id=msg]").removeClass().addClass("alert").addClass('alert-'+type).html(msg); $("[id=msg]").removeClass().addClass("alert").addClass('alert-'+type).html(msg);
} }
function showAjaxError(json) {
showModal(json.responseText.replace(/\n/g, '<br />'), 'Fatal Error请联系作者', 'danger');
}
function isMobile() { function isMobile() {
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
return true; return true;