show error msg when response is not valid JSON

This commit is contained in:
printempw 2016-03-13 16:03:49 +08:00
parent 80dca173a7
commit e5fd39e13c
2 changed files with 15 additions and 5 deletions

View File

@ -1,8 +1,8 @@
/*
* @Author: prpr
* @Date: 2016-01-21 13:55:44
* @Last Modified by: prpr
* @Last Modified time: 2016-02-05 21:11:56
* @Last Modified by: printempw
* @Last Modified time: 2016-03-13 16:00:20
*/
'use strict';
@ -20,12 +20,13 @@ var login = function() {
showMsg('alert-info', '登录中。。');
},
success: function(json) {
console.log(json);
if (json.errno == 0) {
docCookies.setItem('uname', uname, null, '/');
docCookies.setItem('token', json.token, null, '/');
if ($('#keep').prop('checked')) {
docCookies.setItem('uname', uname, 604800, '/');
// 设置长效 token 7天
// 设置长效 cookie 7天
docCookies.setItem('token', json.token, 604800, '/');
}
showAlert(json.msg);
@ -34,6 +35,9 @@ var login = function() {
showAlert(json.msg);
showMsg('hide', '');
}
},
error: function(json) {
showMsg('alert-danger', '出错啦,请联系作者!<br />详细信息:'+json.responseText);
}
});
}
@ -49,7 +53,7 @@ var register = function() {
dataType: "json",
data: {'uname':uname, 'passwd':passwd},
beforeSend: function() {
showMsg('alert-info', 'Registering...');
showMsg('alert-info', '注册中...');
},
success: function(json) {
if (json.errno == 0) {
@ -65,6 +69,9 @@ var register = function() {
showAlert(json.msg);
showMsg('hide', "");
}
},
error: function(json) {
showMsg('alert-danger', '出错啦,请联系作者!<br />详细信息:'+json.responseText);
}
});
}

View File

@ -2,7 +2,7 @@
* @Author: prpr
* @Date: 2016-01-21 13:56:40
* @Last Modified by: printempw
* @Last Modified time: 2016-03-12 21:42:31
* @Last Modified time: 2016-03-13 16:00:48
*/
'use strict';
@ -146,6 +146,9 @@ $("#upload").click(function(){
if (json.cape.errno != 0) {
showMsg('alert-danger', '上传披风的时候出错了:\n'+json.cape.msg);
}
},
error: function(json) {
showMsg('alert-danger', '出错啦,请联系作者!<br />详细信息:'+json.responseText);
}
});
} else {