ajax 的應答錯誤處理
(1)無權限
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuIXY0N3Xu92Yp9CXzV2Zh1WavwVbvNmLllXZ0lmL3gjN5gzN3gjMxcHavw1LcpDc0RHaiojIsJye.png)
if ((data.status && data.status == '401') || (data.statustext && data.statustext == 'no transport')) {
console.log(data);
var currenturl = window.location.href;
window.location.href = currenturl;
return;
}
(2)404或網絡斷開
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuIXY0N3Xu92Yp9CXzV2Zh1WavwVbvNmLllXZ0lmL3gjN5gzN3gjMxcHavw1LcpDc0RHaiojIsJye.png)
if ((data.status && data.status == '404') || (data.statustext && data.statustext == 'not found')
|| (data.statustext && data.statustext == 'error')) {
console.log(data);
this._notice('網絡失敗,請稍後再試');
return;
}
完整示例:
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuIXY0N3Xu92Yp9CXzV2Zh1WavwVbvNmLllXZ0lmL3gjN5gzN3gjMxcHavw1LcpDc0RHaiojIsJye.png)
success:function (data) {
ischeckidentify = false;
$('.sendsmsbtn').removeclass("btn-disable").val("擷取驗證碼");
if ((data.status && data.status == '404') || (data.statustext && data.statustext == 'not found')